Merge pull request #18189 from ringerc/log-trace-id

Add traceID to query logs
This commit is contained in:
Julien 2026-02-26 17:06:48 +01:00 committed by GitHub
commit 02b1abab5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -3746,3 +3746,6 @@ headers:
tls_config:
[ <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.

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