Skip to content

Commit

Permalink
tracing: add trace_id var (http.vars.trace_id placeholder) (#6308)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpi committed May 8, 2024
1 parent dd203ad commit 0b5720f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/caddyhttp/tracing/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0b5720f

Please sign in to comment.