A customer clicks "buy." Four hundred and twenty milliseconds later, the order confirms — or it doesn't, and your on-call engineer gets paged at 3 a.m. with a checkout error rate that jumped from 0.1% to 2%. The question is never "is something broken?" The question is where, among the fifty services that touched that request: the gateway, auth, cart, inventory, pricing, payment, fraud check, the bank's 3D Secure call, the order database, the email service, the warehouse queue — and forty more you forgot existed.

Logs can't answer that question. A log line tells you what one service saw. A trace tells you what the request saw, end to end, with a clock attached to every hop. Distributed tracing is the difference between searching fifty haystacks and reading one timeline.

This is Season 3, Part 7. The benchmark hook today is a detection-rate number with real teeth: at 1% head sampling, you keep 4.8% of a rare endpoint's failures — and the fix, tail sampling, keeps 100% of them at 3.9% of the volume.

The ELI5 version

Imagine a relay race where the baton is passed fifty times, and one runner drops it. Without tracing, you have fifty runners each writing in their own diary: "I ran fine." With tracing, every runner writes their split time on the same baton, so when the baton arrives late you can see exactly which handoff was slow — the bank call took 150 ms of a 420 ms race, and everything else was fast.

The baton is the trace ID: one 128-bit number, generated at the edge, passed in a header (traceparent) to every service the request touches. Each handoff is a span: a named operation with a start time, an end time, and a 64-bit span ID. The spans link parent-to-child, and together they form the trace — a tree of everything one request did, in order.

How it works: IDs, spans, and the collector

The mechanics are deliberately boring, which is why they work at scale:

  1. The edge generates a trace ID. The gateway (or the first instrumented service) mints a random 128-bit trace ID and a 64-bit span ID for the root span, and puts them in the traceparent header: 00-<trace-id>-<span-id>-01. The last two digits are flags — 01 means "sampled, keep this trace."
  2. Every service propagates it. Each downstream call — HTTP, gRPC, a message onto a queue — carries the same trace ID and a new span ID, with the caller's span recorded as the parent. No service needs to know the whole tree; it just passes the baton.
  3. Spans flow to a collector. Services export spans (usually in batches, via OTLP) to an OpenTelemetry Collector, which enriches, batches, and forwards them to a backend — Jaeger, Tempo, Datadog, Honeycomb, your vendor of choice.
  4. The backend stitches the tree. Spans sharing a trace ID are assembled into the waterfall you actually look at during an incident.

Here's the waterfall for one checkout — eleven of its roughly fifty spans:

One checkout's waterfall: the gateway spans the full 420 ms; auth, cart, inventory and pricing run early; payment takes 180 ms with a 150 ms 3D Secure bank call inside it; the order write, email, and warehouse queue finish the request.

Read it the way an on-call engineer does: the gateway bar is the whole request, 420 ms. Everything inside it is a suspect, and the longest bar that isn't explained by its children is the culprit. Here the payment span is 180 ms, and inside it the 3DS bank call is 150 ms — the bank, not your code, is the slow part. Without the trace, you'd be staring at a 420 ms p99 and guessing.

Why it breaks: the volume problem

Tracing's failure mode is not accuracy — it's cost. The arithmetic is brutal and it scales with everything you like about your architecture:

  • 5,000 requests/second × 10 spans per request = 50,000 spans/second
  • 50,000 × 86,400 seconds/day × 30 days ≈ 130 billion spans/month
  • At commercial APM prices, that's roughly $25,000–$60,000 a month — for the privilege of storing mostly healthy 200 OK traces nobody will ever read.

So you sample. And where you sample decides what you can still find.

Head sampling decides at the root span, before the request has done anything: keep this trace or drop it, usually by hashing the trace ID (TraceIdRatioBased, OTEL_TRACES_SAMPLER=parentbased_traceidratio, OTEL_TRACES_SAMPLER_ARG=0.1 for 10%). It is stateless, costs zero extra collector RAM, and works with any load balancer. It is also blind: at the moment of the decision, nobody knows whether this request will succeed, fail, or take ten seconds.

Tail sampling decides after the trace completes: the collector buffers every span, waits out a decision_wait window (typically 10–30 seconds), then keeps the trace if it matches a policy — error status, latency over a threshold, a VIP tenant, plus a small baseline of healthy traffic. It knows how the request ended. The price is state: whole traces sit in collector RAM until the verdict.

The difference shows up exactly where it hurts. An October 2026 simulation study (30 services, 59 endpoints, 2,500 incident trials, 1,247 pipeline configurations) measured it precisely:

  • Head sampling at 1% detected 4.8% of low-traffic endpoint failures, against 89.8% at full fidelity. The rare errors — the ones that only hit one endpoint, a handful of times a day — are the first thing head sampling throws away.
  • Tail sampling matched full-fidelity detection in every incident class, at 3.9% of the span volume, with 25–35 seconds of added delay.

The intuition is simple probability. If an error happens once a day and you keep 1% of traces, you keep that error 1% of the time. Five times a day: 4.9%. Twenty times a day: 18.2%. The errors you most need — the rare ones, the first sign of a new failure — are the ones head sampling is mathematically worst at catching:

Probability of keeping at least one copy of a rare error, vs head-sampling rate, for errors occurring 1, 5, or 20 times a day. At 1% head sampling the once-a-day error is kept 1% of the time; tail sampling keeps 100% of errors at 3.9% of span volume.

The cost arithmetic

Sampling cuts how many spans you keep; it does not fix bloated spans. A span carrying a full request payload or a high-cardinality attribute like a user ID costs the same per span whether you keep 10% or 100%. Trim attributes first, then tune the rate. With that caveat, the ingest math at 10,000 spans/second, 1 KB per span, $0.30/GB:

Monthly ingest cost vs fraction of spans kept: $7,776 at 100%, $3,888 at 50%, $778 at 10%, $304 at tail sampling's 3.9%, $78 at 1%.

Kept Monthly ingest
100% $7,776
50% $3,888
10% (head) $778
3.9% (tail, full detection) $304
1% (head) $78

Tail sampling at 3.9% costs $304 a month and catches what $7,776 catches. Head sampling at 1% costs $78 and catches almost nothing rare. The $226 difference between them is the cheapest incident-detection insurance in your stack — provided the rest of your bill is actually ingestion and retention. If your dominant cost is SDK overhead or cross-zone egress, only an earlier decision helps, because tail sampling still pays to move every span to the collector before dropping it.

And tail sampling has its own bill: RAM. The buffer math is spans/second × decision_wait × bytes/span:

Collector RAM needed to buffer traces until the sampling verdict, vs spans per second, for decision_wait of 10, 15, and 30 seconds. At 50,000 spans/s and a 15 s wait, the buffer is 750 MB.

At 50,000 spans/s with a 15-second wait, the tail tier buffers 750 MB — fine. At a 30-second wait, 1.5 GB, and if the buffer fills, the collector starts dropping whole traces before the policy runs, which silently reintroduces exactly the blindness you bought tail sampling to avoid. The production shape is two tiers: stateless load-balancing collectors that hash every span's trace ID (via the loadbalancingexporter) so all spans of one trace land on the same stateful replica, then the tail-sampling tier with num_traces and memory_limiter bounds set hard. Size the buffer above peak load, or don't run tail sampling at all — a tail sampler that drops under load is worse than head sampling, because it looks like full coverage.

The interview angle

"Design tracing for a 50-service checkout flow" is a system-design interview staple, and the expected answer has a shape:

  1. Propagate a trace ID at the edge (W3C traceparent), one ID per request, parent-child span links, async boundaries (queues, callbacks) propagate too — that's where most real implementations leak.
  2. Sample deliberately, not by default. Head sampling for volume, tail sampling for errors and slow traces, and a stated policy: 100% of errors, 100% of traces over your p99 SLO, 1–2% baseline of healthy traffic.
  3. Name the costs. Spans/second × bytes × retention days is the bill; the collector tier is the operational cost; the decision_wait buffer is the hidden RAM cost.
  4. Say what tracing doesn't do. It doesn't replace metrics (you can't alert on a trace) or logs (a span has no stack trace). The three pillars answer different questions: metrics say something is wrong, traces say where, logs say why.

The common wrong answer is "sample 1% and keep errors" — which is precisely the configuration that keeps 1% of errors. If the interviewer asks one follow-up, it's "how do you keep 100% of errors while storing 4% of spans?" — and the answer is tail sampling with a two-tier collector.

Takeaways

  • A trace is one request's timeline across every service it touched — one 128-bit trace ID, parent-child spans, stitched at the backend.
  • Head sampling is cheap and blind: 1% sampling keeps 1% of your once-a-day errors. It optimises the bill, not the debugging.
  • Tail sampling keeps 100% of errors at ~3.9% of span volume (October 2026 simulation, 2,500 incident trials) — but you pay in collector RAM and a two-tier topology, and an undersized buffer silently drops the traces you wanted most.
  • Do the cost math before the sampling math: spans/s × bytes × seconds × kept fraction × price/GB. At 10k spans/s, tail sampling is $304/mo against $7,776 for everything.
  • Trim attributes before tuning rates. Sampling decides how many spans survive; it never fixes a bloated span.

Next in Season 3: Part 8 — Backups & disaster recovery: RPO/RTO arithmetic. Follow the dev.to profile for the next part.

Companion notebook: the runnable tutorial for this post — download it here (open in Colab/Jupyter).