Documentation
¶
Index ¶
- Constants
- func EnsureTraceID(ctx context.Context) string
- func ExtractFromHeaders(ctx context.Context, headers HeaderAccessor) context.Context
- func GenerateTraceParent() string
- func IDFromContext(ctx context.Context) (string, bool)
- func InjectIntoHeaders(ctx context.Context, headers HeaderAccessor)
- func ParentFromContext(ctx context.Context) (string, bool)
- func StateFromContext(ctx context.Context) (string, bool)
- func WithTraceID(ctx context.Context, traceID string) context.Context
- func WithTraceParent(ctx context.Context, traceParent string) context.Context
- func WithTraceState(ctx context.Context, traceState string) context.Context
- type HeaderAccessor
Constants ¶
const ( // HeaderXRequestID is the standard header name for request tracing HeaderXRequestID = "X-Request-ID" // HeaderTraceParent is the W3C trace context header name HeaderTraceParent = "traceparent" // HeaderTraceState is the W3C trace context "tracestate" header name HeaderTraceState = "tracestate" )
Variables ¶
This section is empty.
Functions ¶
func EnsureTraceID ¶
EnsureTraceID returns an existing trace ID from context or generates a new one
func ExtractFromHeaders ¶
func ExtractFromHeaders(ctx context.Context, headers HeaderAccessor) context.Context
ExtractFromHeaders extracts trace context from transport headers
func GenerateTraceParent ¶
func GenerateTraceParent() string
GenerateTraceParent creates a minimal W3C traceparent header value. Format: version(2)-trace-id(32)-span-id(16)-flags(2), e.g., "00-<32>-<16>-01"
func IDFromContext ¶
TraceIDFromContext returns a trace ID from context if present
func InjectIntoHeaders ¶
func InjectIntoHeaders(ctx context.Context, headers HeaderAccessor)
InjectIntoHeaders writes the trace context (X-Request-ID, traceparent, and optionally tracestate) into the given transport headers. Always overwrites any existing values — the trace ID is forced to align with the traceparent so log/metric correlation across services stays consistent.
Historically this routed through an InjectIntoHeadersWithOptions variant that supported a Preserve mode (set-if-missing). Preserve mode had zero callers across the framework, tools, and tests, so the mode-selector API was removed in W4-H. Add it back with a fresh design if a real consumer need surfaces.
func ParentFromContext ¶
TraceParentFromContext returns a traceparent from context if present
func StateFromContext ¶
TraceStateFromContext returns a tracestate from context if present
func WithTraceID ¶
WithTraceID adds a trace ID to the context
func WithTraceParent ¶
WithTraceParent adds a W3C traceparent value to the context