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 InjectIntoHeadersWithOptions(ctx context.Context, headers HeaderAccessor, opts InjectOptions)
- 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
- type InjectMode
- type InjectOptions
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 injects trace context into transport headers (default: force mode) Backward compatible wrapper over InjectIntoHeadersWithOptions.
func InjectIntoHeadersWithOptions ¶
func InjectIntoHeadersWithOptions(ctx context.Context, headers HeaderAccessor, opts InjectOptions)
InjectIntoHeadersWithOptions injects trace context into headers with configurable behavior
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
Types ¶
type HeaderAccessor ¶
HeaderAccessor provides a simple interface for reading and writing headers
type InjectMode ¶
type InjectMode int
InjectMode controls how headers are written by InjectIntoHeaders
const ( // InjectForce overwrites or aligns headers to ensure consistency with traceparent InjectForce InjectMode = iota // InjectPreserve sets headers only if missing; does not overwrite existing values InjectPreserve )
type InjectOptions ¶
type InjectOptions struct {
Mode InjectMode
}
InjectOptions configures how trace context is injected into headers