Video in progress
How is the trace context passed from one service to another over HTTP?
Through a header: today's standard is W3C Trace Context, the traceparent header. It holds the version, the traceId, the parent span ID and flags. The receiving service continues from this header and links its new span to the same trace.
📖 Answer
The traceparent format:
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
│ │ │ └ flags (01 = sampled)
│ │ └ parent span ID (16 hex)
│ └ trace ID (32 hex)
└ version
When order-service calls payment-service, it opens a new span and sends its ID inside traceparent. Payment-service's filter reads the header and creates its own span as a child of that parent span. As a result the work in both services appears in a single tree.
There is also a tracestate header for vendor-specific data, and baggage for carrying business context (for example, tenantId) along the chain.
In older systems you meet Zipkin's B3 headers (X-B3-TraceId, X-B3-SpanId). If services with two different formats don't understand each other, the trace breaks. So the propagation type must be configured the same in every service.
A trap in practice: if the HTTP client doesn't add the header itself, the context is lost. In Spring Boot you should create a RestTemplate or WebClient not with new but through the auto-configured RestTemplateBuilder / WebClient.Builder / RestClient.Builder, because those are the instrumented ones.
Sign up to mark studied questions and save your progress.