trace

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
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

func EnsureTraceID(ctx context.Context) string

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

func IDFromContext(ctx context.Context) (string, bool)

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

func ParentFromContext(ctx context.Context) (string, bool)

TraceParentFromContext returns a traceparent from context if present

func StateFromContext

func StateFromContext(ctx context.Context) (string, bool)

TraceStateFromContext returns a tracestate from context if present

func WithTraceID

func WithTraceID(ctx context.Context, traceID string) context.Context

WithTraceID adds a trace ID to the context

func WithTraceParent

func WithTraceParent(ctx context.Context, traceParent string) context.Context

WithTraceParent adds a W3C traceparent value to the context

func WithTraceState

func WithTraceState(ctx context.Context, traceState string) context.Context

WithTraceState adds a W3C tracestate value to the context

Types

type HeaderAccessor

type HeaderAccessor interface {
	Get(key string) any
	Set(key string, value any)
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL