-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Current Behavior
When opentelemetry metadata trace_id_source is set to x-request-id and the request-id plugin is enabled (default UUID), requests with X-Request-Id present trigger a Lua runtime error. The request fails and logs show a bad argument error.
Related issues that might be similar:
- help request: Unable to connect to OpenTelemetry #11969
- bug: Trouble with opentelemetry plugin #10389
Expected Behavior
The plugin should validate that x-request-id is a 32-hex trace_id (16 bytes). If invalid (UUID with hyphens, ksuid/nanoid/range_id, empty string, etc.), it should fall back to random trace_id or ignore the header. It should never crash.
We can also consider supporting the generation of a valid trace ID in the request-id plugin.
Error Logs
2025-02-14 14:10:24 2025/02/14 14:10:24 [error] 53#53: *537 lua entry thread aborted: runtime error: bad argument #1 to '?' (invalid value)
2025-02-14 14:10:24 stack traceback:
2025-02-14 14:10:24 coroutine 0:
2025-02-14 14:10:24 [C]: in function 'gsub'
2025-02-14 14:10:24 ...s/share/lua/5.1/opentelemetry/trace/exporter/encoder.lua:22: in function 'hex2bytes'
2025-02-14 14:10:24 ...s/share/lua/5.1/opentelemetry/trace/exporter/encoder.lua:66: in function 'for_otlp'
2025-02-14 14:10:24 ...deps/share/lua/5.1/opentelemetry/trace/exporter/otlp.lua:102: in function 'export_spans'
2025-02-14 14:10:24 ...are/lua/5.1/opentelemetry/trace/batch_span_processor.lua:45: in function 'process_batches'
2025-02-14 14:10:24 ...are/lua/5.1/opentelemetry/trace/batch_span_processor.lua:77: in function
Steps to Reproduce
- Enable the
request-idplugin (default headerX-Request-Id, algorithmuuid). - Set
opentelemetryplugin metadatatrace_id_sourcetox-request-id. - Send a request
- Observe the runtime error and failed request.
Environment
- APISIX version (run
apisix version): - Operating system (run
uname -a): - OpenResty / Nginx version (run
openresty -Vornginx -V): - etcd version, if relevant (run
curl http://127.0.0.1:9090/v1/server_info): - APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run
luarocks --version):
Metadata
Metadata
Assignees
Labels
Type
Projects
Status