Skip to content

fix(query-frontend): restore trace ID in slow query logs#8762

Open
pvlltvk wants to merge 2 commits intothanos-io:mainfrom
pvlltvk:fix/query-frontend-slow-query-trace-id
Open

fix(query-frontend): restore trace ID in slow query logs#8762
pvlltvk wants to merge 2 commits intothanos-io:mainfrom
pvlltvk:fix/query-frontend-slow-query-trace-id

Conversation

@pvlltvk
Copy link
Copy Markdown
Contributor

@pvlltvk pvlltvk commented Apr 9, 2026

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

PR #8618 moved slow query logging into a defer and switched from using w.Header() (ResponseWriter headers) to resp.Header(round-trip response headers). The X-Thanos-Trace-Id header is set on w.Header() by the tracing middleware before the handler runs, so it was never present in resp.Header, causing trace IDs to be missing from slow query logs.

Pass w.Header() to reportQueryStatsAndSlowQueries instead of the response object so the trace ID is available on both success and error paths.

Fixes: #8760

Verification

Added an additional checks for trace ID to TestHandler_SlowQueryLog

PR thanos-io#8618 moved slow query logging into a defer and switched from
using w.Header() (ResponseWriter headers) to resp.Header (round-trip
response headers). The X-Thanos-Trace-Id header is set on w.Header()
by the tracing middleware before the handler runs, so it was never
present in resp.Header, causing trace IDs to be missing from slow
query logs.

Pass w.Header() to reportQueryStatsAndSlowQueries instead of the
response object so the trace ID is available on both success and
error paths.

Fixes: thanos-io#8760

Signed-off-by: Pavel Litvyak <pvlltvk@gmail.com>
Signed-off-by: Pavel Litvyak <pvlltvk@gmail.com>
@zdyj3170101136
Copy link
Copy Markdown

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

upgrade thanos from v0.39.2 to v0.41.0,trace-id loss.

2 participants