Distributed tracing with OpenTelemetry

Spans, context propagation, sampling strategies, the collector pipeline. Turning "the checkout is slow" into the exact hop that burned 800ms.

About 24 min read3-question knowledge check

The mental model

A parcel travels through six depots. Each depot scans it: arrived 14:02, departed 14:04. When the parcel is three days late, you don't interrogate every depot — you pull up the scan history and see that it sat in Nagpur for 62 hours. One view, whole journey, timestamped per hop.

A trace is that scan history for one request. Each hop is a span: a named operation with a start time, a duration, a parent, and attributes. Spans nest into a tree, and the tree is the trace.

trace_id = 4bf92f...  (one user clicking "Pay")

frontend  GET /checkout ................................ 1240ms
  |- auth  POST /verify ............ 42ms
  |- cart  GET /items .............. 88ms
  |- payments POST /charge ..................... 1090ms   <-- here
  |     |- db  SELECT customer ..... 12ms
  |     |- stripe POST /charges ............... 1050ms     <-- actually here
  |- email  POST /receipt (async) .. 15ms

That picture is the entire value proposition. "Checkout is slow" becomes "the Stripe call is taking 1050ms" in about eight seconds of looking, without reading a single log line.

The mechanism that makes it work is **context propagation**: the trace ID and current span ID travel between services in an HTTP header. The W3C standard is traceparent:

traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
             ^  ^                                ^                ^
          version  trace-id (16 bytes)      parent-span-id     flags (01 = sampled)

If any service in the chain drops that header, the trace breaks in two and you lose exactly the correlation you built the system for. This is the single most common tracing bug.

OpenTelemetry (OTel) is the vendor-neutral standard for producing this data: one set of SDKs, one wire protocol (OTLP), plus a Collector that receives, processes and exports to whatever backend you use — Jaeger, Tempo, Datadog, Honeycomb. Instrumentation lives in your code once and the backend becomes a config line. It is a CNCF incubating project and one of the most active projects in the CNCF by contributor activity.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision