You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sh...@apache.org on 2026/04/07 08:26:16 UTC

(apisix) branch master updated: fix(opentelemetry): coerce additional_attributes values to string (#13146)

This is an automated email from the ASF dual-hosted git repository.

shreemaanabhishek 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 eb2eb86e2 fix(opentelemetry): coerce additional_attributes values to string (#13146)
eb2eb86e2 is described below

commit eb2eb86e2424cd9d9c37e1c4eecc284f080b55b4
Author: Mohammad Izzraff Janius <15...@users.noreply.github.com>
AuthorDate: Tue Apr 7 16:26:11 2026 +0800

    fix(opentelemetry): coerce additional_attributes values to string (#13146)
---
 apisix/plugins/opentelemetry.lua |  5 ++--
 t/plugin/opentelemetry.t         | 54 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/apisix/plugins/opentelemetry.lua b/apisix/plugins/opentelemetry.lua
index 3349ed6ec..bf366936d 100644
--- a/apisix/plugins/opentelemetry.lua
+++ b/apisix/plugins/opentelemetry.lua
@@ -49,6 +49,7 @@ local ipairs  = ipairs
 local unpack  = unpack
 local string_format = string.format
 local update_time = ngx.update_time
+local tostring = tostring
 
 local lrucache = core.lrucache.new({
     type = 'plugin', count = 128, ttl = 24 * 60 * 60,
@@ -294,13 +295,13 @@ local function inject_attributes(attributes, wanted_attributes, source, with_pre
             local prefix = key:sub(0, -2)
             for possible_key, value in pairs(source) do
                 if core.string.has_prefix(possible_key, prefix) then
-                    core.table.insert(attributes, attr.string(possible_key, value))
+                    core.table.insert(attributes, attr.string(possible_key, tostring(value)))
                 end
             end
         else
             local val = source[key]
             if val then
-                core.table.insert(attributes, attr.string(key, val))
+                core.table.insert(attributes, attr.string(key, tostring(val)))
             end
         end
     end
diff --git a/t/plugin/opentelemetry.t b/t/plugin/opentelemetry.t
index daf91e39e..597a450f8 100644
--- a/t/plugin/opentelemetry.t
+++ b/t/plugin/opentelemetry.t
@@ -434,3 +434,57 @@ HEAD /specific_status
 tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
 --- response_body eval
 qr/.*\/specific_status.*/
+
+
+
+=== TEST 20: set additional_attributes with numeric nginx variables
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "name": "route_name",
+                    "plugins": {
+                        "opentelemetry": {
+                            "sampler": {
+                                "name": "always_on"
+                            },
+                            "additional_attributes": [
+                                "request_time",
+                                "upstream_response_time",
+                                "bytes_sent"
+                            ]
+                        }
+                    },
+                    "uri": "/opentracing",
+                    "service_id": "1"
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+
+
+
+=== TEST 21: trigger opentelemetry, numeric nginx variables must not cause encode error
+--- request
+GET /opentracing
+--- wait: 2
+--- response_body
+opentracing
+
+
+
+=== TEST 22: check span exported with numeric additional attributes
+--- exec
+tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
+--- response_body eval
+qr/.*opentelemetry-lua.*/