Lesson 16 / 25
Head Sampling
Decide at the start.
Probabilistic decisions in the SDK
Head sampling decides whether to record a trace when its root span starts, before anything is known about the outcome. TraceIdRatioBased keeps a fixed fraction based on the trace ID, and ParentBased samplers follow the parent's decision so traces are not broken across services. It is cheap and simple, but it can drop rare errors and slow requests because the decision is made before they happen.
Keep what matters, drop what does not
Sampling controls volume and cost; processors clean and enrich data before it leaves your network.
Configuring a 10% parent-based sampler
Standard SDK environment variables.
export OTEL_TRACES_SAMPLER=parentbased_traceidratio
export OTEL_TRACES_SAMPLER_ARG=0.1 # root spans: keep 10%; children follow the parentKeep the parent-based wrapper
Without it, services sampling independently produce traces with missing pieces.
Quick check: What is a weakness of head sampling?
- It requires a database
- It is expensive
- It may drop rare errors or slow traces because it decides before the outcome is known
- It cannot be configured
Answer
It may drop rare errors or slow traces because it decides before the outcome is known — Decisions are made up front.