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 <craig.ringer@enterprisedb.com>
This commit is contained in:
Craig Ringer 2026-02-25 12:12:28 +13:00
parent 5d3f9ee39b
commit d4b00499e8

View File

@ -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) {