The most common use case is a client injecting trace context into an RPC request and a server extracting it. This ensures both sides of an operation appear in the same node of the trace tree.
Typical Flow (Multiple Header Encoding):
- Client Tracer has a
TraceContext (TraceId, SpanId, ParentSpanId, Sampling decision). - Client performs Inject operation, creating HTTP headers:
X-B3-TraceIdX-B3-ParentSpanIdX-B3-SpanIdX-B3-Sampled
- Server receives the request and performs Extract to reconstruct the
TraceContext.
NoOp Tracing:
If a service (like a proxy) wants to forbid tracing (e.g., for /health endpoints), it can send a sampling decision independently (e.g., X-B3-Sampled: 0). The receiver then creates a NoOp trace context to minimize overhead.
Client Tracer Server Tracer
┌───────────────────────┐ ┌───────────────────────┐
│ │ │ │
│ TraceContext │ Http Request Headers │ TraceContext │
│ ┌───────────────────┐ │ ┌───────────────────┐ │ ┌───────────────────┐ │
│ │ TraceId │ │ │ X-B3-TraceId │ │ │ TraceId │ │
│ │ │ │ │ │ │ │ │ │ │
│ │ ParentSpanId │ │ │ X-B3-ParentSpanId │ │ │ ParentSpanId │ │
│ │ ├─┼────────>│ ├─────────┼>│ │ │
│ │ SpanId │ │ │ X-B3-SpanId │ │ │ │ SpanId │ │
│ │ │ │ │ │ │ │ │ │ │
│ │ Sampling decision │ │ │ X-B3-Sampled │ │ │ │ Sampling decision │ │
│ └───────────────────┘ │ └───────────────────┘ │ └───────────────────┘ │
│ │ │ │
└───────────────────────┘ └───────────────────────┘