#47 - Tracing explained
A trace ID connects service calls, but gaps in instrumentation hide parts of the request.
16 min read
We discussed tracing before but never got around to explaining details such as fundamentals, terminology, etc. This time Julien goes into detail about what tracing is, what the benefits are, the basic terms you need to understand, and where to start. Great episode for those who are considering adding tracing capabilities to their systems.
Something is slow and nobody can say which hop
A customer clicks a button on your site. That click becomes a request to a backend, the backend calls a service, that service calls another one, and somewhere behind them a database gets read. The page takes nine seconds instead of one. Where do you look first?
If your answer is to ask each team to check their own service, that is the problem. Microservices were adopted at least partly so organisations could ship their org chart: one team, one service, fewer meetings. Conway’s 1968 paper put it the other way round: organisations produce designs that copy their own communication structures. Splitting the system along team lines is the part that worked. The side effect is that the teams don’t talk every day, and when something is slow each team fixes what it can see, which is its own service. The view of the whole request doesn’t live anywhere.
Tracing is how you get that view back. It doesn’t come for free: you end up with a system inside your system that somebody has to maintain. We made the funding argument already, that if you can afford one of logs, metrics and traces you should pick tracing (episode 30). The mechanics are where teams get stuck: the words, the wiring, the gaps in the picture, and the bill.
Span, trace, collector: the whole vocabulary
Start with the words. There are three that matter, and most of the confusion sits in them.
What is a span, and what is a trace?
A span is one recorded operation, and a trace is every span that carries the same trace ID.
The short version of a span, a request between two services, is enough to get started and slightly wrong. The specification is broader: a span represents a single operation within a trace, and spans nest. One call across the network usually produces two, a CLIENT span on the caller and a SERVER span on the receiver. Spans also carry metadata: which service, which operation, how long it took. That is the correlation ID you already stuff into your log lines, with a better data structure behind it, because correlating from text means structured logs, a text store and a lot of patience.
The third word is the collector, and it is the one you can leave out. OpenTelemetry’s own documentation says exporting straight to a backend is a fine way to get value quickly when you are starting out or running something small. A collector is a process whose whole job is to receive, process and export telemetry: your service hands off spans fast, and the collector takes on the retries, the batching and the filtering of sensitive fields. That is why it is the recommendation once you are past the first look.
Either way the spans land in a store you run, and a viewer reads them from there. Grafana 7.0 shipped a trace viewer in May 2020 with Jaeger and Zipkin data sources, so your regular Grafana will show you traces once you point it at a store. Jaeger is where most people start; Grafana Tempo argues you should not pay to index your traces as well as your logs and your metrics. Either way your labels cost something, an index to keep or bytes to scan.
Getting the ID across the wire
The vocabulary is the easy half. The ID has to survive every hop, and that is code.
How does the trace ID get from one service to the next?
It travels with the request: an HTTP header, or gRPC metadata written and read by an interceptor.
On HTTP you add a header, and there is a standard spelling of it. W3C’s trace context recommendation puts a traceparent header on the request, four hyphen-separated fields like 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01. The trace-id field groups the spans; the parent-id says which call came out of which, which is what turns a pile of spans into a readable shape. On gRPC you don’t touch the message at all. You write an interceptor and use the metadata field of the request.
Then comes the work nobody puts in the diagram. Every request your service receives has to be unpacked, the context stored somewhere the rest of the handler can reach, and that context attached to every outgoing call the handler makes. Miss one call site and the trace stops there.
A second cost hides in the same place: finished spans have to leave the process, which is another network call. How many of those calls you make is a configuration choice rather than one per request. The SDK’s batching processor ships them 512 at a time, or every five seconds, on the defaults.
What a trace is worth once you have one
That is a real amount of work, so be clear about what it buys before you ask anyone to fund it.
What does a trace tell you that logs and metrics don’t?
Which hop was slow, in one place, without opening six tools to find out.
The failure you are debugging has changed shape. Services crash less than they used to and degrade more: a page gets slow, a call returns a 404, a pod dies and comes back. A web server falling over told you what to fix. One call in a chain of five getting slower tells you nothing, until you have a graph where the long bar names the service. The trace doesn’t fix the problem, it takes you to where the problem is, which is most of the time you would have spent.
One trace on its own is less useful than it sounds, with one exception: the first one, which draws the dependencies of your service along that request path, every instrumented hop in order. After that the value is in the aggregate, in how much a type of request costs, per service, over a month.
That aggregate is what gets the project funded. Price the resources a request consumes and the ask changes from “tracing would be nice” to “fix this call and we save that many euro, dollar or kronor a month”. How far that stretches is where we don’t agree. Julien’s line is that monitoring answers whether you are making money right now: if the service is up, you probably are. Andrey’s answer was that this is what business intelligence is for.
The map stops where the instrumentation stops
Before you promise anyone a picture of the whole system, be precise about which system the picture is of.
Does a trace show you the whole system?
No. It shows the parts somebody instrumented, and the parts that are missing don’t announce themselves.
A service nobody got round to goes missing in one of two ways, and they look different on screen. If it forwards the context without recording anything, the trace stays whole: the spans either side of it carry the same trace ID and still connect. What is gone is that service’s own work. No span describes it, so the trace says nothing about what happened inside that service. If it doesn’t forward the context, the next instrumented service has no parent to attach to, so it opens a root span, and a root span gets a new trace ID. The request is split across two traces with nothing to join them up.
Third parties are the case you cannot fix: you call someone else’s API, and nothing inside it is yours to instrument. Record a CLIENT span around the call under the context you already have, and you keep what your own service saw: when the call went out, how long it took, whether it failed. The breakdown of what happened on their side is what you lose.
Managed services are the case people miss. A service takes an HTTP request and turns it into a queue message, and our instinct is that the queue is where the chain dies. That is less true than it was: on X-Ray, SQS carries the trace header in a reserved message system attribute called AWSTraceHeader, and AWS added trace linking for SQS and Lambda in November 2022, so a producer, a queue and a consumer can render as one view. SNS is vaguer. AWS has advertised X-Ray for messages passing through SNS since July 2019 without saying what the topic does with your trace header, so check each managed hop yourself.
Our expectation going in is that you see around 90% of the system you set out to instrument, and that the first 80% already pays back the effort. Both are guesses rather than measurements. Where the ID can’t travel at all, a synthetic ID minted at that boundary at least records that something crossed.
Instrumenting is a project, not a change
Coverage is a scheduling problem as much as a technical one, because the code you need changed mostly belongs to other people.
How much work is instrumenting a service?
It depends on your stack and how many teams must change code, and the agreement is harder to get than the code is to write.
Every service imports a library, and the libraries have to line up: the same conventions, the same propagation, and the spans of one request arriving somewhere you can read that trace whole. Nothing says every team must export to the same place; what breaks the trace is spans from the same request landing in two stores that never meet. So the task starts with asking another team to put work into their sprint for a benefit nobody can show them yet. It is not “install this and it works”, and the documentation around it is usually poor. It is not a two-hour change, and you really have to plan for it.
How much code you touch depends on the language. Python’s agent monkey-patches popular libraries at runtime, which means HTTP instrumentation without touching your code, so if that is your stack you can get something running fast and cheap. Some frameworks implement it too, and if yours does, turn it on. Go is the other end. Its documentation was blunt about it: Go does not support truly automatic instrumentation the way other languages do, so you depend on instrumentation libraries and wrap things yourself. Reading that felt like a serious lift rather than a library import.
Whatever you pick, pick something other systems speak. OpenTelemetry came out of the merger of OpenTracing and OpenCensus, and CNCF archived OpenTracing in January 2022, which is as clear a signal as you get about where to put the work. Tracing is its mature half: the tracing API and SDK have been stable since the specification’s 1.0 release, while logs were still experimental in the December 2022 release.
The service mesh shortcut, and where it stops
If the code change is what blocks you, there is a route that starts outside the code.
Can a service mesh do the instrumentation for you?
Partly. The sidecar already sees the traffic it proxies, so it can emit the spans for those hops without you editing a call site.
The AWS version is App Mesh, where your service talks plain HTTP to an Envoy sidecar and the sidecar routes on from there, over TLS if you configure it. The hop from your application to its own proxy stays unencrypted either way, so the proxy can read the headers and report the spans itself. That is why the wiring on your side is so small: set ENABLE_ENVOY_XRAY_TRACING on the sidecar and it sends its segments to the X-Ray daemon at 127.0.0.1:2000. That setup is a colleague’s implementation rather than ours, so treat the detail as second-hand. Istio has its own integrations, and even a load balancer can join in: Traefik supports six tracing backends and defaults to Jaeger.
Know where it stops before you sell it internally. A call to an HTTPS endpoint outside the mesh probably doesn’t go through the sidecar at all, and if it does, the proxy can’t decrypt it to read the headers. The proxy also sees requests, not intent: it can’t tell which outbound call came out of which inbound one, so your application still has to copy the trace headers across. What you save is the span reporting and most of the plumbing, and since your service probably already carries a request ID in context, the change that remains is light.
Sidecars may not be where this ends up. We have heard of people running a mesh without them, in the kernel with eBPF, and the projects are moving that way: Istio introduced ambient mode in September 2022, a data plane that runs without sidecar proxies.
Overhead, sampling and the surprise bill
Volume is where tracing stops being a design discussion and starts being an invoice.
What does tracing cost you at runtime?
CPU and memory inside the service, network to export the spans, and storage for every trace you keep.
Start with the service itself. The middleware parses every inbound request, builds the context and instruments the outbound calls, so each request does more work and your service gets less out of its resources. You may have to give it more. The middleware is also code somebody wrote: we have had one leak memory until it crashed the service it was meant to observe.
Then the collection side. If you are serving a lot of requests per second, recording all of them is expensive, so you set a sampling rate: 1% of traffic, or half of that. At that volume a small sample still shows you the shape. Head sampling decides at the root span, and a dropped span discards its attributes and events and never reaches the exporter, so recording and export both go away and only the context still has to be passed on every hop. Tail sampling moves the decision to a collector, which buffers spans for a configured decision_wait, 30 seconds by default, then applies its policies. Your services keep recording every span and exporting it to the collector, so nothing is saved on that leg. What drops is everything after it: what the collector forwards, what your backend ingests, and what you store.
Know the default before you accept it: X-Ray’s default rule records the first request each second and 5% of everything after that. We learned the rest the expensive way. What X-Ray’s sampling configuration documented and what it did were not the same thing, we ended up recording 100% of traffic, and at $5 per million traces recorded that is a bill you dispute on a customer’s behalf. It was a bug on the X-Ray side and it was fixed, but the lesson generalises.
If the whole project is too big for this quarter, there is a cheaper picture. VPC flow logs record srcaddr, dstaddr, protocol, packets and bytes per flow, so you get who talks to whom and over what, without per-request latency or application-level detail. We have been building a small visualisation on top of them, and it is turning out more useful than expected.
What this means for teams
Where we landed: tracing is the signal that changes what you can know, and the one that costs political capital rather than money up front. The vocabulary takes ten minutes and the propagation is a small amount of code in an awkward place. The project is everything around those two: the other teams, the services nobody will instrument, the managed hops where the chain breaks, and the sampling rate that decides most of the bill. That is why it keeps losing to another logging rollout.
Four things worth doing this week:
- Pick one request path across two services and carry a trace ID end to end, header in, context stored, context attached to the outbound call. Two services are enough to find out what instrumentation costs in your stack.
- Check what automatic instrumentation exists for your language and framework before anyone commits to a date. Python has an agent that instruments common libraries for you; Go expects you to wire instrumentation libraries up by hand.
- Draw the path and mark every hop where the ID can’t travel: third-party APIs, queues, anything managed. Record a client span at each boundary so you keep the duration you can see.
- Set the sampling rate explicitly, deploy it somewhere with light traffic, and look at the bill a week later before it goes anywhere near production volume.
Common questions, answered
Why does my trace stop halfway through a request?
Check where trace context stops propagating, starting with the outbound call from the last visible service. One call site that doesn’t attach the context breaks the chain and raises no error, so the service on the other end never learns there was a trace to join. A service that receives the context and doesn’t pass it on leaves the next instrumented service with no parent, so that one opens a root span with a fresh trace ID and the request ends up split across two traces that nothing joins. A hop that forwards the context but records nothing fails more quietly: the spans either side of it stay in the same trace, and only that service’s own work is missing.
Should I use my cloud provider’s tracing or OpenTelemetry?
Instrument against OpenTelemetry and send the data wherever you like, because the expensive half of this work is the instrumentation and you don’t want to repeat it. Check what your backend supports before you commit, and prefer one that speaks a standard other systems speak too, so changing your mind later is a configuration change rather than a second project. A provider’s own agent can still be the fastest route to a first result, especially where its managed services are already wired into it.
How do I keep an AWS X-Ray bill from surprising me?
Set the sampling rate yourself rather than inheriting a default, and verify what gets recorded against what you configured before production traffic hits it. We have had the documented behaviour and the real behaviour disagree on X-Ray, ended up recording everything, and disputed the charges on a customer’s behalf. It was a bug and it was fixed, but the pattern is general: record a small percentage of a high-volume service, and watch the trace count somewhere quiet first.
Related episodes
- Three pillars of observability: why we would fund tracing first if we could fund only one of the three.
- Do I need a service mesh?: the longer version of the mesh argument, including what the sidecars cover.
- Monitoring Done Wrong or Dreaming for a Better Monitoring: why debugging a microservices system from logs is slow and expensive.
Resources
- Trace Context, W3C Recommendation, February 2020: settles what a request carries for spans to join up, a
traceparentheader with atrace-idand aparent-id. - Trace API, OpenTelemetry specification v1.16.0, December 2022: settles what a span is, a single operation rather than a hop, and why one remote call produces two.
- CNCF archives the OpenTracing project, January 2022: settles which standard the ecosystem converged on, and what became of the one before it.
- Distributed tracing overview, Istio 1.16: settles what a mesh does not do for you, naming the headers your application still has to propagate.
- Configuring sampling rules, AWS X-Ray documentation: settles what you get if you never touch sampling: one request per second plus 5% of the rest.
Since we recorded
OpenTelemetry finished the set it was missing: the logs bridge API and SDK were marked stable in specification v1.21.0 in May 2023, so one project now standardises all three signals rather than two and a half. The Go complaint has an answer: otelc compiles instrumentation into your binary and reached its first stable release in 2026. The App Mesh shortcut has run out: AWS set 30 September 2026 as the end of support for App Mesh, after which its console and resources are no longer reachable, and points teams at Amazon ECS Service Connect instead. X-Ray moved the same way: its SDKs and daemon entered maintenance mode on 25 February 2026, and AWS recommends OpenTelemetry for instrumentation instead.
