Skip to content

Lesson 2 of 13 · 13m

Head Sampling Throws Away the Traces You Wanted

Deciding at the root drops the rare errors you needed; collector tail sampling keeps them at a memory cost.

A 1% head sampler decides whether to keep a trace at the moment the root span opens — before anyone knows the request's outcome. It keeps 1% of your boring 200s and 1% of the once-a-day p99.9 outliers you actually needed. Errors are rare by definition; multiply rare by a small sampling probability and you have zero. This is the trap: sampling strategies that decide early are cheap precisely because they ignore everything that makes a trace worth keeping.

Head sampling

Head (or probability) sampling hashes the trace ID against a ratio — OpenTelemetry's parentbased_traceidratio — so every span in a trace makes the same keep/drop decision. Consistent, stateless, near-free. It's the right default for uniform traffic where you're measuring distributions rather than hunting anomalies. It is the wrong tool when the anomaly is the deliverable.

Two subtleties worth knowing. First, parentbased_* samplers honor the parent's sampled flag, so a decision made upstream propagates honestly instead of producing half-sampled traces (orphan spans that claim to belong to a trace nobody stored). Consistency is what makes a ratio work across hops at all: if each service re-rolled the dice, a five-service request at 10% per-service keep would survive at 10⁻⁵. Second, there's a difference between recording and sampling: an SDK can record every span and ship it all to a collector that samples later. The "always-on" sampler isn't a contradiction — it's how tail sampling gets fed.

Tail sampling

Tail sampling buffers every span of a trace until the trace completes, then decides with full information: did any span end in ERROR? Did end-to-end latency exceed 800 ms? If yes, keep the whole trace; if no, keep a quota of successes. The OpenTelemetry Collector's tail_sampling processor does exactly this, holding spans in memory for decision_wait (default 30 s) after the first span of a trace arrives, then evaluating a policy list:

processors:
  tail_sampling:
    decision_wait: 30s
    num_traces: 100000
    policies:
      - name: errors
        type: status_code
        status_code: {status_codes: [ERROR]}
      - name: slow
        type: latency
        latency: {threshold_ms: 800}
      - name: baseline
        type: probabilistic
        probabilistic: {sampling_percentage: 5}

and, composite, rate_allocation, span_count, numeric_attribute, and ottl_condition policies cover the cases where a single clause isn't enough — "slow AND on the payments service," "keep at most 500 slow traces per second."

The costs are real and worth stating. Full-fidelity egress: every span travels to the collector even if 95% get dropped, so bandwidth cost doesn't shrink. Memory: num_traces × your average spans-per-trace × span size is the working set; expected_new_traces_per_sec pre-sizes the internal index, and when the buffer fills the processor drops whole traces — the very outliers you paid to keep. Latency blindness: decision_wait bounds how late a straggler span can arrive — if your slowest hop is a queue consumer with minutes of lag, raise it or accept partial traces that fail the latency policy by incompleteness. And a trace that never completes within the wait still gets judged; incomplete traces are policy candidates, not orphans.

What actually runs in production

Jaeger's remote and adaptive sampling adjust per-service probabilities toward a target spans-per-second rate — useful when one noisy endpoint would otherwise dominate your keep budget. Honeycomb's Refinery is a standalone tail-sampling proxy doing the same job for OTLP-shaped traffic. Either way, the design is identical: decide late, keep errors, quota the boring.

The concrete rule: if you can afford the egress, sample in the collector, not the SDK. Keep 100% of ERROR status traces, add a latency policy a notch above your SLO, and rate-limit the rest. If you can't afford it, at least move the sampling decision to the edge where the response status is known — a sampler that knows the outcome beats one guessing at the root.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.