diff options
author | Matthew Penner <[email protected]> | 2024-05-08 16:40:40 -0600 |
---|---|---|
committer | GitHub <[email protected]> | 2024-05-08 16:40:40 -0600 |
commit | 0b5720faa548269c865941c384956ba45e98f015 (patch) | |
tree | 5be2c9d9c1b80f87ffec5f78a2b245a208e395a8 /modules | |
parent | dd203ad41f15872939e327f0b399366cb13f2287 (diff) | |
download | caddy-0b5720faa548269c865941c384956ba45e98f015.tar.gz caddy-0b5720faa548269c865941c384956ba45e98f015.zip |
tracing: add trace_id var (`http.vars.trace_id` placeholder) (#6308)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/tracing/tracer.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/caddyhttp/tracing/tracer.go b/modules/caddyhttp/tracing/tracer.go index ecd415fa0..89c617bf4 100644 --- a/modules/caddyhttp/tracing/tracer.go +++ b/modules/caddyhttp/tracing/tracer.go @@ -87,8 +87,12 @@ func (ot *openTelemetryWrapper) serveHTTP(w http.ResponseWriter, r *http.Request ot.propagators.Inject(ctx, propagation.HeaderCarrier(r.Header)) spanCtx := trace.SpanContextFromContext(ctx) if spanCtx.IsValid() { + traceID := spanCtx.TraceID().String() + // Add a trace_id placeholder, accessible via `{http.vars.trace_id}`. + caddyhttp.SetVar(ctx, "trace_id", traceID) + // Add the trace id to the log fields for the request. if extra, ok := ctx.Value(caddyhttp.ExtraLogFieldsCtxKey).(*caddyhttp.ExtraLogFields); ok { - extra.Add(zap.String("traceID", spanCtx.TraceID().String())) + extra.Add(zap.String("traceID", traceID)) } } next := ctx.Value(nextCallCtxKey).(*nextCall) |