From d4b00499e8cf3bd1ca770202ef285c8b3e7d784a Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Wed, 25 Feb 2026 12:12:28 +1300 Subject: [PATCH] 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) {