In this lesson · topic 1 of 7
Topic 1
Why one request needs a trace
4 min read
A request is not one program
When a user presses a button, one service rarely does all the work. A gateway calls a catalog service, which calls a search index and a cache. A pricing service calls a database, then a second store. Some of those calls run side by side and some wait for each other. When the page is slow, the question is not whether the system is slow. It is where this request spent its time.
You already have two tools. Metrics tell you that the p99 of the gateway is high. Logs tell you what each service did, in the order it did it. Neither one joins the story across services. A metric is an aggregate, so it has forgotten which request was which. A log line from the pricing service has no idea which gateway request caused it, unless someone put an identifier there.
What a trace adds
A trace is the record of one request and everything it caused, drawn as a tree. Each node is a span: one timed operation, with a start, an end and a parent. Every span in a request carries the same trace identifier, so the pieces from different services can be put back together.
In the lab’s default tree a request goes two tiers deep, and every service calls three others. That is 13measured spans for one request, with 12measured calls below the gateway. A request in which every call takes its average time needs 69 msmeasured end to end. Across the simulated traffic the median is 76 msmeasured and the p99 is 248 msmeasured. A latency chart would tell you the tail is slow. Only the trace of one slow request tells you which of those calls it was.
Predict first
The cost is the reason for the design
Putting an identifier on every call and recording a span for every operation adds work to every request. It also produces a lot of data: one span per call, for every request, forever. The rest of the lesson is about how tracing systems stay cheap enough to leave on, and what you lose when they do.