Inferensys

Glossary

Span Context

Span context is the immutable state, containing trace ID, span ID, trace flags, and trace state, that is propagated across process boundaries to enable distributed tracing.
Elegant overhead shot of a polished wooden communal table in a sun-drenched WeWork lounge, laptops and tablets displaying AI workflow dashboards, plants and pendant lights in background.
DISTRIBUTED TRACE COLLECTION

What is Span Context?

Span context is the immutable state that must be propagated across process boundaries, containing the trace ID, span ID, trace flags, and trace state, enabling distributed tracing.

Span context is the immutable metadata packet that must be propagated across service and process boundaries to maintain the continuity of a distributed trace. It contains the core identifiers—trace ID, span ID, trace flags (for sampling decisions), and trace state (for vendor-specific data)—that allow downstream services to correctly link their operations to the originating request. This context is typically injected into and extracted from transport protocols like HTTP headers or message queues using a propagator component.

The W3C Trace Context standard formalizes the header format for this propagation, ensuring interoperability between different tracing systems. Without accurate span context propagation, spans become orphaned, breaking the end-to-end trace and making it impossible to reconstruct the full request flow for performance analysis or debugging. In OpenTelemetry, the span context is a fundamental object managed by the tracing SDK.

DISTRIBUTED TRACE COLLECTION

Key Components of Span Context

Span context is the immutable, portable state that must be propagated across process boundaries to maintain trace continuity. It contains the core identifiers and metadata that enable correlation of work in a distributed system.

01

Trace ID

A Trace ID is a globally unique, 16-byte or 128-bit identifier assigned to a single request's end-to-end journey. It is the primary correlation key, shared by every span within the same trace. This ID is generated by the root service (the trace's initial entry point) and must remain constant as the request propagates. It allows observability backends to group all related spans, reconstructing the complete request flow across services, queues, and databases.

02

Span ID

A Span ID is a unique identifier for a single, specific unit of work within a trace. Unlike the Trace ID, it is local to its span. This ID is used to establish parent-child relationships between spans, forming the hierarchical structure of a trace. When a service calls another, the child span's ID is different from its parent's, but the parent's Span ID is recorded in the child's context as the parent span ID. This creates the directed acyclic graph (DAG) that visualizes call paths.

03

Trace Flags

Trace Flags are a set of binary options carried in the span context that control tracing behavior. The most critical flag is the sampling bit. A value of 1 means the trace is sampled and should be recorded and exported to the backend. A value of 0 means it is not sampled. This decision, often made by the root service via head sampling, is propagated to all downstream services, ensuring they respect the sampling decision and avoid generating telemetry for unsampled requests, controlling cost and volume.

04

Trace State

Trace State is a key-value map carried in the span context that provides additional, vendor-specific tracing information. It is designed for multi-vendor interoperability. For example, one tracing system can add an entry (vendorname=value) that another system can read and propagate without understanding its full semantics. It is used for features like:

  • Passing sampling probabilities
  • Carrying proprietary debug flags
  • Encoding authentication tokens for trace ingestion Unlike other context fields, Trace State is mutable, allowing services to update their respective entries.
05

Propagation Formats (W3C, B3)

Span context is useless unless it can be transmitted. Propagation formats define the wire protocol for encoding context into carriers like HTTP headers or message metadata. The two primary standards are:

  • W3C Trace Context: The modern, vendor-neutral W3C recommendation. Uses headers traceparent (carries Trace ID, Span ID, flags) and tracestate.
  • B3 Propagation: The format pioneered by Zipkin. Uses headers prefixed X-B3-, such as X-B3-TraceId and X-B3-SpanId. Tracing libraries use propagators to inject (outbound) and extract (inbound) context using these formats.
06

Immutable vs. Propagated Data

It is crucial to distinguish between the immutable span context and the mutable span data. The context (Trace ID, Span ID, Flags, State) is the portable 'passport' that is propagated. The span's attributes (e.g., http.method=GET), events, status, and duration are recorded locally by each service and are not part of the propagated context. They are exported separately as span data and linked via the Span ID. This separation ensures the lightweight context propagation does not balloon with diagnostic details.

DISTRIBUTED TRACE COLLECTION

How Span Context Propagation Works

Span context propagation is the mechanism that enables distributed tracing by passing immutable trace state between services.

Span context propagation is the process of serializing and transmitting an immutable span context—containing the trace ID, span ID, trace flags, and trace state—across process boundaries. This is typically achieved via HTTP headers (using standards like W3C Trace Context) or messaging system metadata. A propagator component within a tracing library handles the injection of this context into outbound requests and its extraction from inbound requests, ensuring trace continuity.

This propagation enables the reconstruction of a complete distributed trace, forming a directed acyclic graph of spans. Without it, each service would create isolated, uncorrelated spans. The mechanism is foundational to end-to-end tracing, allowing observability backends to link work performed across heterogeneous services, databases, and asynchronous processes for latency analysis and fault diagnosis.

WIRE FORMATS

Common Span Context Propagation Formats

A comparison of standardized protocols for transmitting trace and span identifiers across service boundaries in distributed systems.

Feature / ProtocolW3C TraceContextB3 (Zipkin)Jaeger (uber-trace-id)

Standardization Body

W3C Recommendation

OpenZipkin Community

Jaeger (CNCF)

Primary Header(s)

traceparent, tracestate

X-B3-TraceId, X-B3-SpanId, X-B3-ParentSpanId, X-B3-Sampled

uber-trace-id

Trace ID Format

32-hex char (16 bytes), lowercase

32 or 16-hex char (vendor-specific)

128-bit, encoded as 32 hex chars

Span ID Format

16-hex char (8 bytes), lowercase

16-hex char (8 bytes)

64-bit, encoded as 16 hex chars

Sampling Decision Flag

Included in traceparent flags field

Separate X-B3-Sampled header (1/0)

Encoded in uber-trace-id packed format

Support for Additional State

tracestate header (key-value list)

Limited; often requires custom headers

Limited; often requires custom headers

Built-in Support for Span Links

No explicit support in header

Default Propagation in OpenTelemetry

SPAN CONTEXT

Frequently Asked Questions

Span context is the immutable state that must be propagated across process boundaries, containing the trace ID, span ID, trace flags, and trace state, enabling distributed tracing. These FAQs address its core mechanics and role in observability.

Span context is the immutable, portable state object that must be propagated across service and process boundaries to maintain the continuity of a distributed trace. It contains the essential identifiers and metadata that allow different components of a system to link their individual operations (spans) back to a single overarching request (trace). The primary components are the trace ID, span ID, trace flags (which control sampling decisions), and trace state (for carrying vendor-specific information). Without the correct propagation of span context, spans become orphaned, breaking the end-to-end view of a request's journey and crippling debugging and performance analysis.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.