mirror of
https://github.com/caddyserver/caddy.git
synced 2025-11-12 09:36:53 -05:00
feat: inject span_id as var and log context
This commit is contained in:
parent
c2ccf8690f
commit
e35ce3d005
@ -88,11 +88,15 @@ func (ot *openTelemetryWrapper) serveHTTP(w http.ResponseWriter, r *http.Request
|
|||||||
spanCtx := trace.SpanContextFromContext(ctx)
|
spanCtx := trace.SpanContextFromContext(ctx)
|
||||||
if spanCtx.IsValid() {
|
if spanCtx.IsValid() {
|
||||||
traceID := spanCtx.TraceID().String()
|
traceID := spanCtx.TraceID().String()
|
||||||
|
spanID := spanCtx.SpanID().String()
|
||||||
// Add a trace_id placeholder, accessible via `{http.vars.trace_id}`.
|
// Add a trace_id placeholder, accessible via `{http.vars.trace_id}`.
|
||||||
caddyhttp.SetVar(ctx, "trace_id", traceID)
|
caddyhttp.SetVar(ctx, "trace_id", traceID)
|
||||||
|
// Add a span_id placeholder, accessible via `{http.vars.span_id}`.
|
||||||
|
caddyhttp.SetVar(ctx, "span_ud", spanID)
|
||||||
// Add the trace id to the log fields for the request.
|
// 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", traceID))
|
extra.Add(zap.String("traceID", traceID))
|
||||||
|
extra.Add(zap.String("spanID", spanID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next := ctx.Value(nextCallCtxKey).(*nextCall)
|
next := ctx.Value(nextCallCtxKey).(*nextCall)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user