Key takeaways
- ✓Per-service metrics blame every caller of a slow service: in the rounds where payments was 50 ms slower, the gateway, orders and payments all showed a p50 rise of 67 to 71 ms, because each service's time includes waiting for the services it calls.
- ✓A trace is one request as a tree of timed steps (spans), and its critical path is the chain of steps that request actually waited on: in the lab, the top of the critical path was the slowed service in 50 of 50 traces in each of the five slowed rounds.
- ✓Recording every checkout at 400 a second cost 27% more CPU per checkout (3.29 ms to 4.19 ms, across the seven service processes) and about 1 ms more at the median (8.27 ms to 9.31 ms).
- ✓Switching the tracing library on while recording nothing cost 10% more CPU, and recording one checkout in ten cost 20%, so sampling saved about 7 points of CPU in this run; the bigger saving that sampling offers is storage, which the lab did not measure.
- ✓At 800 checkouts a second, recording everything roughly doubled the median repetition's p50, from about 8.7 ms to about 16.9 ms, because pricing was using about 0.9 of a core and extra work turned into waiting in line.
- ✓The 50 of 50 result is the easy case by construction: the 50 ms was a planted pause inside the slowed service's own step, which normally takes three or four ms, so a real slowdown is rarely this clean.
A checkout passed through five services. One of them was made 50 ms slower, and the code that looks for it was not told which. The per-service metrics flagged three services in the rounds where payments was the slow one. One trace per request named the right service every time. Then the bill: recording every checkout took about a quarter more processor time. This chapter takes the two views apart, shows what each one can and cannot say, and then measures what tracing costs.
The examples come from Lab 21 (SLOs and Observability) of the system design labs. The scripts are 03_tracing.py for the slow-service test and 04_overhead.py for the cost, and their recorded results are in data/results/. The lab ran on an Apple M4 Max with Docker Desktop (16 virtual CPUs). The five services, Prometheus, Jaeger and the collector all ran in Docker on that one laptop. Each number below is from one recorded run of the lab, so it is a measurement of this setup, not a general claim about tracing.
The checkout path
A checkout goes through a gateway, which hands it to orders. Orders asks inventory and pricing at the same time, and then calls payments. After the answer has gone back to the user, two more services finish the job: a relay, which picks up new orders from the database every 100 ms, and a notifier, which sends the "order placed" message.
Two words recur. Prometheus stores metrics: numbers per service, counted over many requests. Jaeger stores and shows traces: one record per request. The services record their trace data with OpenTelemetry, an open standard with a library for each language. A library that records the data for a request is part of what this chapter calls tracing.
Why the metrics blame three services
A metric is a number per service, counted over many requests. The lab's metric is the p50 of each service's server time: the typical time it took to answer, where half the requests were faster and half slower. A p99 is the slowest one in a hundred.
The trouble is that a service's time includes the time it spent waiting for the services it calls. Think of a parcel moving through five depots. Each depot's typical time includes the time its parcels sat waiting for the next depot. When one depot is slow, every depot before it reports a slow typical time, so the report shows several depots in trouble, and it cannot say which one is at fault.
In the lab's runs, a 50 ms delay in payments raised three services' p50:
- Gateway rose 67.5 ms, and orders rose 67.5 ms, though neither was slowed.
- Payments rose 71.4 ms, the only one that had been slowed.
So the metrics named three suspects, using a rule of a p50 rise above 40 ms. When orders was slowed, the two suspects were the gateway and orders itself, because inventory, pricing and payments are called by orders and never wait on it. When the gateway was slowed, it was the only suspect, because nothing above it waits on anything.
One detail: a 50 ms delay read as 67.5 ms. Each service does not keep every time. It counts requests in buckets, such as 50 to 100 ms, and the p50 is read off the bucket. Nearly every request fell in one bucket, so the lab's best guess is the bucket's middle: 7.5 ms before and 75 ms after, a rise of 67.5. The bucket edges set the number you see.
What a trace is
A trace is one request's whole journey. It is a tree of spans: one span per step, each with a service name, a start time and an end time. The checkout's trace in the lab had 11 spans, including the async steps that ran after the response.
A trace shows where one request spent its time, but a trace also has a problem: with parallel calls, the sum of all the spans is not the time that mattered. Inventory and pricing ran at the same time, so only the one that finished last delayed orders. The critical path is the chain of steps the request actually waited on. The lab computes it by walking backwards from the end of the request: find the call that finished last before this point, count the gap after it as the parent's own time, then jump to that call's start and repeat.
The widget below shows the two views side by side, for the same round. The left side is the metrics. The right side is one trace from that round, showing the critical-path time for each service.
Only payments got 50 ms slower. Checkout p50 rose from 8.6 ms to 59.4 ms.
Metrics: p50 rise vs normal, ms
Suspect = rise above 40 ms. The 50 ms delay reads as 67–74 ms because the p50 comes from histogram buckets (50 to 100 ms).
3 suspects: gateway, orders, payments
One trace: critical-path time, ms
The first of the round's 50 traced checkouts. Critical path: the stops this request actually waited on, which with parallel calls is one of inventory or pricing, not both.
Top: payments · in 50 of 50 traces of this round
In every round, the top of the critical path was the slowed service in 50 of 50 traces. The lab's first trace in the payments round had payments at 54.39 ms of critical path, and every other service at 2.00 ms or less. In the normal round, the top was payments at 3.27 ms, because it waits on the card network in the lab. A trace always has a top, so it is only meaningful next to a normal trace.
Two more things happened after the checkout returned. The "order placed" message went out a median of about 61 to 76 ms after the checkout returned, depending on the round. Most of that is the relay: it polls every 100 ms, so a new order waits about 50 ms on average. A trace that keeps going after the response shows this, which is part of why an asynchronous tail is worth looking at in the same trace.
The test and its workflow
The lab's test has six rounds, each 20 seconds at 100 checkouts a second, with every request traced. The first round is normal. Each of the next five slows one service by 50 ms, in a seeded random order. The script learns which service was slowed only after it has scored its readings, so the readings cannot be tuned to the answer.
The two readings are automated. For metrics, the script compares each service's p50 with the normal round and calls every service whose p50 rose by more than 40 ms a suspect. For traces, it reads one trace at a time, with no comparison, and blames the service with the most time on that trace's critical path. These are stand-ins for a person looking at a dashboard and at Jaeger. They show what each view contains, not how quickly a person would read it.
| Slowed service | Checkout p50 | Metrics: suspects | Trace: top of the critical path |
|---|---|---|---|
| none (normal) | 8.6 ms | none | payments, 50 of 50 |
| orders | 59.6 ms | gateway, orders | orders, 50 of 50 |
| pricing | 59.4 ms | gateway, orders, pricing | pricing, 50 of 50 |
| inventory | 59.2 ms | gateway, orders, inventory | inventory, 50 of 50 |
| payments | 59.4 ms | gateway, orders, payments | payments, 50 of 50 |
| gateway | 59.6 ms | gateway | gateway, 50 of 50 |
The metrics named every caller of the slow service, and the trace named only the slow service. The slowed service's own step was the one that had grown; its callers' own time did not change. Reading the metrics alone, a person would have to know the call graph to tell the callers from the culprit.
What tracing costs
The cost test ran the same checkout load at 400 and at 800 checkouts a second, 20 seconds per run, five repetitions per mode, with the order rotated between them. It compared four modes:
- Tracing off: no OpenTelemetry library at all.
- Library on, nothing recorded: the library runs, but no spans are kept.
- Record 1 in 10: one checkout in ten is recorded (this is sampling: keeping only a fraction of traces).
- Record every checkout: all 11 spans of each checkout are built, serialized and sent to the collector (the OpenTelemetry collector, a service that receives spans and passes them on to storage).
At 400 checkouts a second, the pooled results over five repetitions were:
| Mode | p50 | CPU per checkout (7 services) | CPU vs tracing off |
|---|---|---|---|
| Tracing off | 8.27 ms | 3.29 ms | |
| Library on, nothing recorded | 8.64 ms | 3.63 ms | +10% |
| Record 1 in 10 | 9.07 ms | 3.95 ms | +20% |
| Record every checkout | 9.31 ms | 4.19 ms | +27% |
Recording every checkout cost 1.04 ms at the median, and about a quarter more processor time. Two things about sampling surprised. First, the library being on, with nothing recorded, already cost 10%: every request still creates a span that is not recorded, passes the trace's identifier along, and runs the sampler (the code that decides whether a trace is kept). Second, recording one checkout in ten still cost another 10 points, which is more than its tenth of the full 27%. In this run, the lab cannot say why, so the lesson is narrow: do not count on sampling to cut processor time. Sampling saves the recording, the sending and the storing, and the bigger saving in production is likely storage, which the lab did not measure.
At 800 checkouts a second, the pooled p50 rose from 9.87 ms with tracing off to 17.37 ms with every checkout recorded, and CPU rose 22%. Two repetitions stalled, one in each of two modes: one with tracing off had a p50 of 300 ms and 202 failed requests, and one with 1 in 10 recorded had 756 failed requests. Those stalls pull the pooled p50s up. Taking each mode's median repetition instead (computed from the lab's per-repetition file) gives about 8.7 ms with tracing off and about 16.9 ms with everything recorded. The lab's explanation is queueing: pricing used about 0.9 of a core in every fully traced repetition, so the extra work turned into waiting in line.
Pooled p50 over 5 repetitions, 20 s each. CPU is the processor time of the 7 service processes per checkout. The collector and Jaeger are not counted.
Caveats
- The delay was planted, and it was clean. The 50 ms was a sleep inside the slowed service's own step, which normally takes three or four ms. By construction the trace could not miss it. A real slowdown is rarely that tidy, so the 50 of 50 result is the easy case.
- The readings are automated. The script stood in for a person reading a dashboard and Jaeger. It does not time how long a person needs.
- One busy laptop. The machine had a load average of about 10 to 12 on 16 CPUs during the cost runs, and other containers were running. The p99 varied about 4 times between repetitions of the same mode, and one repetition with tracing off had a p99 of 5.2 seconds. The lab reports p50 and CPU as its measurements and does not rely on the tail.
- CPU counts only the seven service processes. The collector, which receives the spans, and Jaeger, which stores them, were not counted, so the true cost of tracing is higher.
- Storage was not measured. The lab did not record how much data the traces took, so it cannot say how big the storage bill is or how much sampling saves there.
- Not covered: tail-based sampling (keeping the slow and failed traces and sampling the rest), more than five services, other request types, loads above 800 a second, and the cost of the collector and Jaeger themselves.
The checklist
- Read the metrics as a list of callers, not culprits. A slow service raises every service above it by the same amount.
- Read a trace by its critical path. Walk back from the end, find the step the request waited on, and compare with a normal trace.
- Count tracing's fixed cost. The library on, with nothing recorded, cost 10% CPU at 400 checkouts a second, before any sampling.
- Measure the tail on a quiet machine. The median was stable across repetitions here; the p99 was not.
- Price storage separately. Sampling's bigger saving is likely in storage, and this lab did not measure it.
Quiz
1.When only payments is 50 ms slower, the per-service metrics also show gateway and orders about 67 ms slower. Why do the callers look guilty?
2.One trace shows payments at 54.4 ms on its critical path and every other step at 2 ms or less. What does that tell you about this request?
3.At 400 checkouts a second, recording one checkout in ten (sampling) cost about 20% more CPU per checkout than tracing off. Why not about 2%?
Check your understanding
Try each question before opening its answer.
Why did the gateway and orders show a p50 rise of about 67 ms when only payments was slowed?
Because each service's time includes the time it spent waiting for the services it calls. The gateway waits on orders, and orders waits on payments, so a 50 ms delay in payments reaches both of them. The metrics alone cannot tell which service caused the delay, because they do not show who called whom. The trace shows which step the request waited on.
A trace has payments at 54.4 ms on its critical path, and nothing else above 2 ms. Does that prove payments did 54 ms of work?
Not by itself. The critical path shows where the request waited, and in the lab the delay was a planted pause inside payments' own step, so the time was payments' own. In a real system the wait could also be a call that payments made to something else. The trace shows where to look next, so the next step is to compare with a normal trace and check what that step was doing.
Why did recording one checkout in ten still cost about 20% more CPU at 400 a second, instead of about 2%?
Because the library's fixed work for each request runs whether or not the request is recorded: creating the span, passing the trace's identifier along and running the sampler. That work alone cost 10%. Sampling removes only the recording and sending. The lab's run recorded one in ten and still lost another 10 points, which it could not fully explain, so do not count on sampling to cut processor time.
At 800 checkouts a second, the pooled p50 with everything recorded is 17.4 ms, but the median repetition is about 16.9 ms. Which number should you quote?
Say which one you mean. The pooled p50 is the lab's summary over all five repetitions. The median repetition ignores a single outlier, and it is the fairer comparison for the tracing-off and one-in-ten modes, where a stalled repetition pulled the pooled p50 far up. For the full-recording mode no repetition stalled, so the two numbers are close.
Next up: Cost per request, the next episode: SLOs written as Prometheus rules and tested like code, and what a million requests cost.