Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ A/B testing, canary release, blue-green deployment, limit rate, defense against
- **OPS friendly**

- Zipkin tracing: [Zipkin](docs/en/latest/plugins/zipkin.md)
- OpenTelemetry tracing: [OpenTelemetry](docs/en/latest/plugins/opentelemetry.md) with plugin execution tracing
- Open source APM: support [Apache SkyWalking](docs/en/latest/plugins/skywalking.md)
- Works with external service discovery: In addition to the built-in etcd, it also supports [Consul](docs/en/latest/discovery/consul.md), [Consul_kv](docs/en/latest/discovery/consul_kv.md), [Nacos](docs/en/latest/discovery/nacos.md), [Eureka](docs/en/latest/discovery/eureka.md) and [Zookeeper (CP)](https://github.com/api7/apisix-seed/blob/main/docs/en/latest/zookeeper.md).
- Monitoring And Metrics: [Prometheus](docs/en/latest/plugins/prometheus.md)
Expand Down
36 changes: 34 additions & 2 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,9 @@ function _M.run_plugin(phase, plugins, api_ctx)
return api_ctx
end

-- Get OpenTelemetry plugin for tracing
local otel_plugin = _M.get("opentelemetry")

if phase ~= "log"
and phase ~= "header_filter"
and phase ~= "body_filter"
Expand All @@ -1188,11 +1191,26 @@ function _M.run_plugin(phase, plugins, api_ctx)
goto CONTINUE
end

-- Start OpenTelemetry plugin span
if otel_plugin and otel_plugin.start_plugin_span then
otel_plugin.start_plugin_span(api_ctx, plugins[i]["name"], phase)
end

run_meta_pre_function(conf, api_ctx, plugins[i]["name"])
plugin_run = true
api_ctx._plugin_name = plugins[i]["name"]
local code, body = phase_func(conf, api_ctx)
api_ctx._plugin_name = nil

-- Finish OpenTelemetry plugin span
if otel_plugin and otel_plugin.finish_plugin_span then
local error_msg = nil
if code and code >= 400 then
error_msg = "plugin returned error code: " .. tostring(code)
end
otel_plugin.finish_plugin_span(api_ctx, plugins[i]["name"], phase, error_msg)
end

if code or body then
if is_http then
if code >= 400 then
Expand All @@ -1216,7 +1234,6 @@ function _M.run_plugin(phase, plugins, api_ctx)
end
end
end

::CONTINUE::
end
return api_ctx, plugin_run
Expand All @@ -1226,11 +1243,26 @@ function _M.run_plugin(phase, plugins, api_ctx)
local phase_func = plugins[i][phase]
local conf = plugins[i + 1]
if phase_func and meta_filter(api_ctx, plugins[i]["name"], conf) then
-- Start OpenTelemetry plugin span
if otel_plugin and otel_plugin.start_plugin_span then
otel_plugin.start_plugin_span(api_ctx, plugins[i]["name"], phase)
end

plugin_run = true
run_meta_pre_function(conf, api_ctx, plugins[i]["name"])
api_ctx._plugin_name = plugins[i]["name"]
phase_func(conf, api_ctx)

local code = phase_func(conf, api_ctx)
api_ctx._plugin_name = nil

-- Finish OpenTelemetry plugin span
if otel_plugin and otel_plugin.finish_plugin_span then
local error_msg = nil
if code and code >= 400 then
error_msg = "plugin returned error code: " .. tostring(code)
end
otel_plugin.finish_plugin_span(api_ctx, plugins[i]["name"], phase, error_msg)
end
end
end

Expand Down
Loading