mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
tracing: add trace_id var (http.vars.trace_id
placeholder) (#6308)
This commit is contained in:
parent
dd203ad41f
commit
0b5720faa5
1 changed files with 5 additions and 1 deletions
|
@ -87,8 +87,12 @@ func (ot *openTelemetryWrapper) serveHTTP(w http.ResponseWriter, r *http.Request
|
||||||
ot.propagators.Inject(ctx, propagation.HeaderCarrier(r.Header))
|
ot.propagators.Inject(ctx, propagation.HeaderCarrier(r.Header))
|
||||||
spanCtx := trace.SpanContextFromContext(ctx)
|
spanCtx := trace.SpanContextFromContext(ctx)
|
||||||
if spanCtx.IsValid() {
|
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 {
|
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)
|
next := ctx.Value(nextCallCtxKey).(*nextCall)
|
||||||
|
|
Loading…
Reference in a new issue