This is an automated email from the ASF dual-hosted git repository.
shreemaan-abhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new d2f94b024 fix(opentelemetry): give inject_core_spans its own tracer
cache key (#13633)
d2f94b024 is described below
commit d2f94b0246107f2db7700ab91565eb4d40706a15
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Thu Jul 2 18:15:54 2026 +0800
fix(opentelemetry): give inject_core_spans its own tracer cache key (#13633)
---
apisix/plugins/opentelemetry.lua | 5 +++--
t/plugin/opentelemetry.t | 44 +++++++++++++++++++++++++++++++++++-----
2 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/apisix/plugins/opentelemetry.lua b/apisix/plugins/opentelemetry.lua
index f046460cd..7ec44edd0 100644
--- a/apisix/plugins/opentelemetry.lua
+++ b/apisix/plugins/opentelemetry.lua
@@ -450,8 +450,9 @@ local function inject_core_spans(root_span_ctx, api_ctx,
conf)
additional_attributes = conf.additional_attributes,
additional_header_prefix_attributes =
conf.additional_header_prefix_attributes
}
- -- key the cache on modifiedIndex so the tracer is rebuilt when metadata
changes
- local tracer, err = core.lrucache.plugin_ctx(lrucache, api_ctx,
metadata.modifiedIndex,
+ -- separate key from the rewrite tracer; modifiedIndex rebuilds it on
metadata change
+ local cache_key = "inject_core_spans#" .. tostring(metadata.modifiedIndex)
+ local tracer, err = core.lrucache.plugin_ctx(lrucache, api_ctx, cache_key,
create_tracer_obj,
inject_conf, plugin_info)
if not tracer then
core.log.error("failed to fetch tracer object: ", err)
diff --git a/t/plugin/opentelemetry.t b/t/plugin/opentelemetry.t
index b1ba88516..8287a99ea 100644
--- a/t/plugin/opentelemetry.t
+++ b/t/plugin/opentelemetry.t
@@ -648,24 +648,46 @@ qr/.*x-injected-by-plugin.*test-value.*/
=== TEST 29: updating plugin_metadata rebuilds the cached tracer on a warm
worker
+--- extra_yaml_config
+apisix:
+ tracing: true
+plugins:
+ - opentelemetry
--- config
location /setup_first {
content_by_lua_block {
local t = require("lib.test_admin").test
local plugin = require("apisix.plugin")
- t('/apisix/admin/plugin_metadata/opentelemetry', ngx.HTTP_PUT,
+ local code, body =
t('/apisix/admin/plugin_metadata/opentelemetry', ngx.HTTP_PUT,
[[{"batch_span_processor":{"max_export_batch_size":1,"inactive_timeout":0.5},"collector":{"address":"127.0.0.1:4318"},"resource":{"service.name":"otel-meta-change-first"}}]])
- t('/apisix/admin/routes/1', ngx.HTTP_PUT,
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+ code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT,
[[{"plugins":{"opentelemetry":{"sampler":{"name":"always_on"}}},"upstream":{"nodes":{"127.0.0.1:1980":1},"type":"roundrobin"},"uri":"/opentracing"}]])
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
-- wait until this worker sees the metadata so the warm-up span
uses it
+ local seen
for _ = 1, 50 do
local m = plugin.plugin_metadata("opentelemetry")
if m and m.value and m.value.resource
and m.value.resource["service.name"] ==
"otel-meta-change-first" then
+ seen = true
break
end
ngx.sleep(0.1)
end
+ if not seen then
+ ngx.status = 500
+ ngx.say("metadata did not propagate")
+ return
+ end
ngx.say("ok")
}
}
@@ -673,17 +695,29 @@ qr/.*x-injected-by-plugin.*test-value.*/
content_by_lua_block {
local t = require("lib.test_admin").test
local plugin = require("apisix.plugin")
- t('/apisix/admin/plugin_metadata/opentelemetry', ngx.HTTP_PUT,
+ local code, body =
t('/apisix/admin/plugin_metadata/opentelemetry', ngx.HTTP_PUT,
[[{"batch_span_processor":{"max_export_batch_size":1,"inactive_timeout":0.5},"collector":{"address":"127.0.0.1:4318"},"resource":{"service.name":"otel-meta-change-second"}}]])
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
-- wait until this worker sees the updated metadata before the
next span
+ local seen
for _ = 1, 50 do
local m = plugin.plugin_metadata("opentelemetry")
if m and m.value and m.value.resource
and m.value.resource["service.name"] ==
"otel-meta-change-second" then
+ seen = true
break
end
ngx.sleep(0.1)
end
+ if not seen then
+ ngx.status = 500
+ ngx.say("metadata did not propagate")
+ return
+ end
ngx.say("ok")
}
}
@@ -695,8 +729,8 @@ qr/.*x-injected-by-plugin.*test-value.*/
-=== TEST 30: last exported span must carry the updated service.name, not the
stale one
+=== TEST 30: core span from inject_core_spans must carry the updated
service.name
--- exec
-tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
+grep apisix.phase.access ci/pod/otelcol-contrib/data-otlp.json | tail -n 1
--- response_body eval
qr/otel-meta-change-second/