Documentation
¶
Index ¶
Constants ¶
const ( TraceparentHeader = "traceparent" TracestateHeader = "tracestate" )
W3C Trace Context header names
Variables ¶
This section is empty.
Functions ¶
func ContextWithTraceContext ¶
func ContextWithTraceContext(ctx context.Context, tc *TraceContext) context.Context
ContextWithTraceContext returns a new context with the TraceContext attached.
Types ¶
type TraceContext ¶
type TraceContext struct {
// TraceID is the 32-character hex-encoded trace identifier
TraceID string
// SpanID is the 16-character hex-encoded span/parent identifier
SpanID string
// TraceFlags is the trace flags byte (e.g., 0x01 for sampled)
TraceFlags byte
// TraceState is the optional vendor-specific trace state
TraceState string
}
TraceContext holds W3C Trace Context fields. See: https://www.w3.org/TR/trace-context/
func FromContext ¶
func FromContext(ctx context.Context) *TraceContext
FromContext extracts TraceContext from context. Returns nil if no TraceContext is found.
func FromHTTPHeaders ¶
func FromHTTPHeaders(headers http.Header) *TraceContext
FromHTTPHeaders extracts W3C Trace Context from HTTP headers. Returns nil if no valid traceparent header is found.
func FromHTTPHeadersOrNew ¶
func FromHTTPHeadersOrNew(headers http.Header) (*TraceContext, error)
FromHTTPHeadersOrNew extracts W3C Trace Context from HTTP headers, or generates a new one if not found.
func NewTraceContext ¶
func NewTraceContext() (*TraceContext, error)
NewTraceContext generates a new TraceContext with random trace ID and span ID.
func ParseTraceparent ¶
func ParseTraceparent(header string) (*TraceContext, bool)
ParseTraceparent parses a W3C traceparent header value. Format: {version}-{trace-id}-{parent-id}-{trace-flags} Example: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01
func (*TraceContext) IsSampled ¶
func (tc *TraceContext) IsSampled() bool
IsSampled returns true if the sampled flag is set.
func (*TraceContext) SetHTTPHeaders ¶
func (tc *TraceContext) SetHTTPHeaders(headers http.Header)
SetHTTPHeaders sets W3C Trace Context headers on an HTTP request.
func (*TraceContext) ToTraceparent ¶
func (tc *TraceContext) ToTraceparent() string
ToTraceparent formats the TraceContext as a W3C traceparent header value.