Distributed tracing
One slow checkout, five machines, and no single log that explains it. Seven steps build up spans, the trace ID that links them, and the waterfall that points at the slow hop.
In 30 seconds
One click often passes through many services. Distributed tracing records that journey so you can see where the time went.
Each service records a span: one timed piece of work. All spans of one request share a trace ID, which every service passes along with its calls, and each span names its parent.
Put together, the spans form a waterfall that shows the slow hop at a glance. Systems usually keep only a sample of traces, and OpenTelemetry is the open standard for producing them.
Distributed tracing, step by step
IDs are shortened: a real trace ID is 32 hex characters and a span ID 16. The final 01 in the header means “sampled”. Timings are invented for the example.
- Step 1: One click, five machines. A shopper presses Pay. The request goes to a gateway, which calls the orders service, which calls inventory and payments, and payments calls the bank. The page took 900 ms. Each service sees only its own slice of the request and writes its own log, so nobody can say where the time went.
- Step 2: A span: one timed piece. Tracing starts with the span: a record of one piece of work in one service, with a name, a start time and a duration. The orders service records a span for creating the order, from 20 ms after the request began until 880 ms: 860 ms long. Every service records spans like this for the work it does.
- Step 3: A trace: spans of one request. A trace is the set of all spans that belong to one request. Two fields tie them together. Every span carries the same trace ID, here 4bf9, so they can be collected from all the services. And every span names its parent, the span that caused it, which arranges them into a tree of who called whom.
- Step 4: Passing the trace ID along. The services share no memory, so the IDs have to travel with the request. The first service invents the trace ID. Whenever a service calls another, it adds a header holding the trace ID and its own span ID. The receiver copies the trace ID and uses that span ID as the parent of its new span. This is called context propagation.
- Step 5: Waterfall: find the slow hop. A tracing tool collects the five spans by their trace ID and draws them on one time axis, each under its parent: a waterfall. The answer is now visible. The gateway, orders and payments bars are long only because they are waiting. The time is spent in the call to the bank: 690 of the 900 ms.
- Step 6: Sampling: keep only some. Recording every span of every request is costly, so most systems keep a sample. Head sampling decides at random at the first service, say 1 in 100, and the decision travels with the trace ID so all services agree. Tail sampling waits until a trace is complete and keeps the interesting ones: errors and slow requests.
- Step 7: OpenTelemetry. OpenTelemetry is a widely adopted open standard for all of this. It provides libraries for many languages that create spans and pass the trace ID along, a common protocol (OTLP) for sending them, and a collector that can forward them. The tool that stores and draws the traces can be swapped without changing the services.
Try it yourself
Learn this first
Spotted a mistake on this page?