Distributed Tracing Explained: Spans, Sampling and Finding Slow Requests

How distributed tracing works across microservices: traces and spans, context propagation, reading waterfall views, head vs tail sampling, Jaeger and Tempo.

Published December 4, 2026

In a monolith, a profiler tells you where a slow request spends its time. In a microservice system, one user request may touch ten services, two queues and three databases. Distributed tracing reconstructs that whole journey as a single trace, so you can see exactly which hop was slow or failed.

The concept

A trace is a tree of spans. Each span represents one operation, an HTTP handler, a database query, a call to another service, with a start time, duration, status and attributes. Child spans record work done on behalf of their parent. Trace context (a trace ID and parent span ID) is propagated in request headers and message metadata so spans created in different services are stitched together.

Tracing every request can be expensive at high volume, so systems sample. Head-based sampling decides at the start of a trace (for example keep 10%), which is cheap but may miss rare errors. Tail-based sampling, typically in the OpenTelemetry Collector, waits until a trace completes and keeps all errors and slow traces plus a sample of normal ones.

Reading a trace

GatewayCheckoutInventoryPaymentsPOST /checkout (2.4 s total)reserve stock (80 ms)okcharge card (1.9 s!)ok201
The waterfall immediately shows payments dominating latency.

Sampling strategies

SamplingDecidesProsCons
Head-based (probabilistic)At trace startCheap, simpleMisses rare errors
Tail-basedAfter trace completesKeeps errors and slow tracesNeeds buffering in a Collector
Always on (100%)EverythingComplete dataExpensive at scale

Where the time went

Checkout handler2.4 s totalPayments call1.9 sInventory call80 msDB writes120 ms
Span durations from one slow trace.

Practical examples

Propagate context through a message queue

Inject on publish, extract on consume.

from opentelemetry import propagate, trace
tracer = trace.get_tracer("orders")

# producer
headers = {}
propagate.inject(headers)
queue.publish(body, headers=headers)

# consumer
ctx = propagate.extract(message.headers)
with tracer.start_as_current_span("process_order", context=ctx):
    process(message.body)

Tail sampling in the Collector

Keep errors and slow traces, sample the rest.

processors:
  tail_sampling:
    decision_wait: 10s
    policies:
      - { name: errors, type: status_code, status_code: { status_codes: [ERROR] } }
      - { name: slow, type: latency, latency: { threshold_ms: 1000 } }
      - { name: sample, type: probabilistic, probabilistic: { sampling_percentage: 5 } }

Run Jaeger locally

All-in-one image with OTLP ingestion and UI.

docker run --rm -p 16686:16686 -p 4317:4317 -p 4318:4318 jaegertracing/jaeger:latest
# UI: http://localhost:16686

Common mistakes

  • Broken propagation at async boundaries, splitting one request into many traces.
  • Head sampling at 1% and wondering why error traces are missing.
  • Spans without useful attributes (route, status, IDs).
  • Tracing without linking logs to trace IDs.

Key takeaways

  • A trace is a tree of spans stitched together by propagated context.
  • Waterfall views reveal slow or failing hops instantly.
  • Tail sampling keeps the traces that matter.
  • Propagate context through queues and link logs to traces.

FAQ

Do I need tracing for a monolith?

It still helps show database and external call timing, but its biggest value appears with multiple services.

Jaeger or Tempo?

Both are open-source trace backends; Tempo is optimised for cheap object storage and Grafana integration, Jaeger has a mature standalone UI.

Does tracing add latency?

Overhead is small with batching exporters; sampling controls volume and cost.

More DevOps articles