# Head Sampling — OpenTelemetry

Source: https://www.skillbyai.com/en/opentelemetry/s-head

> 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.

![Three ideas: head sampling, tail sampling, processing and redaction.](assets/figures/opentelemetry/section-6-map.svg) — Figure 6.1 — Head sampling, tail sampling and processing.

## Configuring a 10% parent-based sampler

Standard SDK environment variables.

```bash
export OTEL_TRACES_SAMPLER=parentbased_traceidratio
export OTEL_TRACES_SAMPLER_ARG=0.1     # root spans: keep 10%; children follow the parent
```

## Keep the parent-based wrapper

Without it, services sampling independently produce traces with missing pieces.

**Quiz:** What is a weakness of head sampling?

- [ ] It requires a database
- [ ] It is expensive
- [x] 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.
