fix(opentelemetry): coerce additional_attributes values to string#13146
Merged
shreemaan-abhishek merged 4 commits intoApr 7, 2026
Conversation
janiussyafiq
force-pushed
the
fix/ot-handle-nonstring
branch
from
April 3, 2026 03:23
a9adf61 to
b2afa2e
Compare
shreemaan-abhishek
previously approved these changes
Apr 6, 2026
nic-6443
reviewed
Apr 7, 2026
| --- response_body | ||
| opentracing | ||
| --- no_error_log | ||
| bad argument #2 to 'encode' |
Member
There was a problem hiding this comment.
Remove this specific error message and simply assert that there are no error logs at all. Because if a specific error message is set, problems may fail to be detected due to changes in the error message.
Contributor
Author
There was a problem hiding this comment.
good catch! fixed
Baoyuantop
approved these changes
Apr 7, 2026
nic-6443
approved these changes
Apr 7, 2026
shreemaan-abhishek
approved these changes
Apr 7, 2026
5 tasks
shreemaan-abhishek
added a commit
that referenced
this pull request
May 7, 2026
…ghten test (#13315) Three follow-ups to #13146 (which started coercing additional_attributes values to strings before sending them to OTel attr.string): 1. inject_attributes() gated insertion on `if val then`, which silently drops boolean false (Lua falsy) — regressing any user whose nginx variable resolves to a boolean false flag. Switch to `if val ~= nil then` so false survives. 2. ngx.req.get_headers() returns a Lua table for multi-value headers (e.g. multiple Set-Cookie / X-Forwarded-For entries). tostring() over a table emits 'table: 0x...' and that's what was landing in the span attribute. Extract a coerce_attr_value() helper that joins multi-value entries with ', ' and skips when the source is missing entirely. 3. TEST 22's response_body regex was qr/.*opentelemetry-lua.*/ which matches the OTLP exporter marker even when the numeric attributes are entirely absent from the export — i.e. the test would still pass with the regression #13146 was supposed to fix. Tighten it to assert each of request_time / bytes_sent appears as a stringValue. (upstream_response_time is intentionally not asserted: TEST 21 serves /opentracing directly without proxying, so $upstream_response_time is nil and the plugin correctly omits the attribute.) Signed-off-by: Shreemaan Abhishek <[email protected]> Signed-off-by: Abhishek Choudhary <[email protected]>
wistefan
pushed a commit
to wistefan/apisix
that referenced
this pull request
Jun 16, 2026
wistefan
pushed a commit
to wistefan/apisix
that referenced
this pull request
Jun 16, 2026
…ghten test (apache#13315) Three follow-ups to apache#13146 (which started coercing additional_attributes values to strings before sending them to OTel attr.string): 1. inject_attributes() gated insertion on `if val then`, which silently drops boolean false (Lua falsy) — regressing any user whose nginx variable resolves to a boolean false flag. Switch to `if val ~= nil then` so false survives. 2. ngx.req.get_headers() returns a Lua table for multi-value headers (e.g. multiple Set-Cookie / X-Forwarded-For entries). tostring() over a table emits 'table: 0x...' and that's what was landing in the span attribute. Extract a coerce_attr_value() helper that joins multi-value entries with ', ' and skips when the source is missing entirely. 3. TEST 22's response_body regex was qr/.*opentelemetry-lua.*/ which matches the OTLP exporter marker even when the numeric attributes are entirely absent from the export — i.e. the test would still pass with the regression apache#13146 was supposed to fix. Tighten it to assert each of request_time / bytes_sent appears as a stringValue. (upstream_response_time is intentionally not asserted: TEST 21 serves /opentracing directly without proxying, so $upstream_response_time is nil and the plugin correctly omits the attribute.) Signed-off-by: Shreemaan Abhishek <[email protected]> Signed-off-by: Abhishek Choudhary <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When using the
opentelemetryplugin withadditional_attributesthat reference Nginx variables returning numeric values (e.g.request_time,upstream_response_time,bytes_sent), APISIX crashes with the following error during span export:This happens because
inject_attributes()always callsattr.string(key, val)regardless of the actual Lua type of the value. Theresty.ngxvarlibrary returns Lua numbers for certain Nginx variables, and the OTLP protobuf encoder strictly expects a string forstring_value, causing it to abort.The fix wraps all values with
tostring()before passing them toattr.string(). This is correct because Nginx variables are conceptually always strings —tostring()simply restores that invariant thatresty.ngxvarbreaks for numeric variables.Which issue(s) this PR fixes:
Fixes #9921
Checklist