Overview
Trace context includes:- Trace ID: Unique identifier for the entire trace
- Span ID: Unique identifier for the current span
- Parent Span ID: Links spans together
- Sampling decision: Whether the trace is sampled
- Trace flags: Metadata about the trace
SpanContextData
Frompackages/core/src/types-hoist/span.ts:
Getting Trace Context
From Active Span
From Scope
PropagationContext
Stored on the scope for trace propagation:Setting Propagation Context
Trace Headers
sentry-trace Header
Format:{trace_id}-{span_id}-{sampled}
baggage Header
Contains dynamic sampling context:Continuing Traces
continueTrace
Continue a trace from incoming headers:From HTML Meta Tags (Browser)
Dynamic Sampling Context
Additional context for sampling decisions:Getting DSC
Root Span
Get the root span of the current trace:Trace ID Generation
Span Relationships
Custom Parent Span
Sampling Decisions
Trace State
OpenTelemetry trace state for vendor-specific data:Implementation Example
Frompackages/core/src/tracing/trace.ts: