From d4b00499e8cf3bd1ca770202ef285c8b3e7d784a Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Wed, 25 Feb 2026 12:12:28 +1300 Subject: [PATCH 1/2] Add traceID to query logs The query log embeds a spanID, but omits the traceID, making log/trace correlation significantly more difficult. Add the trace ID as well. This might be better done with the otelslog wrapper in https://github.com/go-slog/otelslog but this change is more minimal. This does not add trace and span IDs to other logging emitted to Prometheus's standard logger during the processing of activities in which traces may be active. Fixes #18188 Signed-off-by: Craig Ringer --- promql/engine.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/promql/engine.go b/promql/engine.go index a769310e46..3505102b9b 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -700,7 +700,11 @@ func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, ws annota } f = append(f, slog.Any("stats", stats.NewQueryStats(q.Stats()))) if span := trace.SpanFromContext(ctx); span != nil { - f = append(f, slog.Any("spanID", span.SpanContext().SpanID())) + spanCtx := span.SpanContext() + f = append(f, + slog.Any("spanID", spanCtx.SpanID()), + slog.Any("traceID", spanCtx.TraceID()), + ) } if origin := ctx.Value(QueryOrigin{}); origin != nil { for k, v := range origin.(map[string]any) { From 158647fb45216d0ee1b9e84aaeab30e413124286 Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Wed, 25 Feb 2026 13:13:59 +1300 Subject: [PATCH 2/2] Document traceID / spanID injection in query log Signed-off-by: Craig Ringer --- docs/configuration/configuration.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 060319ae92..1525269441 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -3746,3 +3746,6 @@ headers: tls_config: [ ] ``` + +If query logging and tracing are both enabled, a traceID and spanID will be injected +into the query log file for use in log/trace correlation.