Skip to content

bug: opentelemetry trace_id_source=x-request-id crashes with request-id plugin #12976

@ronething

Description

@ronething

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:

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

  1. Enable the request-id plugin (default header X-Request-Id, algorithm uuid).
  2. Set opentelemetry plugin metadata trace_id_source to x-request-id.
  3. Send a request
  4. Observe the runtime error and failed request.

Environment

  • APISIX version (run apisix version):
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -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

Labels

bugSomething isn't workingplugin

Type

No type

Projects

Status

🏗 In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions