-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(opentelemetry): validate x-request-id before using it as trace_id #12990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9828d17
3f93a20
28e8dbc
b0bd8fb
a7a3225
ccde264
66a9196
d21f243
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -434,3 +434,104 @@ HEAD /specific_status | |||||||||||||||||||||||||||||
| tail -n 1 ci/pod/otelcol-contrib/data-otlp.json | ||||||||||||||||||||||||||||||
| --- response_body eval | ||||||||||||||||||||||||||||||
| qr/.*\/specific_status.*/ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| === TEST 20: recreate route for invalid x-request-id test | ||||||||||||||||||||||||||||||
| --- 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, | ||||||||||||||||||||||||||||||
| [[{ | ||||||||||||||||||||||||||||||
| "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 | ||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||
| ngx.say(body) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| --- request | ||||||||||||||||||||||||||||||
| GET /t | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| === TEST 21: invalid x-request-id should not crash | ||||||||||||||||||||||||||||||
| --- request | ||||||||||||||||||||||||||||||
| GET /opentracing | ||||||||||||||||||||||||||||||
| --- more_headers | ||||||||||||||||||||||||||||||
| X-Request-Id: 550e8400-e29b-41d4-a716-446655440000 | ||||||||||||||||||||||||||||||
| --- wait: 2 | ||||||||||||||||||||||||||||||
| --- response_body | ||||||||||||||||||||||||||||||
| opentracing | ||||||||||||||||||||||||||||||
| --- no_error_log | ||||||||||||||||||||||||||||||
| [error] | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| [error] | |
| [error] | |
| === TEST 22: invalid x-request-id should still generate a trace_id | |
| --- request | |
| GET /opentracing | |
| --- more_headers | |
| X-Request-Id: 550e8400-e29b-41d4-a716-446655440000 | |
| --- wait: 2 | |
| --- grep_error_log eval | |
| qr/trace_id/ | |
| --- grep_error_log_out | |
| trace_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation function should reject trace IDs that are all zeros (00000000000000000000000000000000) according to the W3C Trace Context specification. Currently, the function only checks length and hex format, but an all-zeros trace_id is invalid and should be rejected to ensure proper fallback to the default generator.