Sampling is the unglamorous decision that quietly determines whether your tracing bill is $60 or $6,000 a month, and whether the one trace you need during an incident is actually there. The two strategies (deciding before the request finishes or after) sound like an implementation detail and aren't, because one of them can keep every error trace and the other can't.
Why sample at all
A fully-instrumented request generates 5-20 spans. At 1,000 req/s (86.4 million requests a day) that's roughly 430 million to 1.7 billion spans a day. At about 1 KB per span that's roughly 430 GB to 1.7 TB a day, before retention. Storage adds up quickly. Sampling trades data volume for cost.
Head-based sampling
Decide at the root span. A deterministic hash of the trace ID lets distributed services agree on the same decision: a trace either lives or dies across every service it touches.
use OpenTelemetry\SDK\Trace\Sampler\TraceIdRatioBasedSampler;
use OpenTelemetry\SDK\Trace\TracerProvider;
$sampler = new TraceIdRatioBasedSampler(0.1); // keep 10%
$tracerProvider = TracerProvider::builder()
->setSampler($sampler)
->build(); Pros: cheap (no buffering), works cross-service, little operational complexity. Cons: you throw away traces before knowing whether they were errors or slow. At a 10% rate you drop 90% of all traces, and that includes about 90% of your errors and slow requests.
Tail-based sampling
Buffer every span for a fixed window, keyed by trace ID (decision_wait, 30 seconds by default). The Collector has no signal that a trace is finished, so when the window ends it applies the rules to whatever spans have arrived.
processors:
tail_sampling:
decision_wait: 30s
num_traces: 50000
policies:
- name: errors-always
type: status_code
status_code:
status_codes: [ERROR]
- name: slow-always
type: latency
latency:
threshold_ms: 1000
- name: sample-normal
type: probabilistic
probabilistic:
sampling_percentage: 10 Pros: keep all errors, keep all slow traces, sample the rest. Much better data quality per dollar. Cons: you need Collectors with enough memory to buffer all in-flight traces, and every span of a trace has to reach the same Collector instance, which in a cluster means a load-balancing tier that routes by trace ID.
Hybrid approach
Many production systems combine both: head-sample at 100% (keep everything) through a Collector that then applies tail rules. The head-sampler stops being a sampler and becomes a pass-through; the tail rules do the actual filtering.
Which one to actually pick
The honest decision tree is short. Under a few hundred requests a second, keep everything. Sampling solves a problem you don't have yet, and the full dataset is worth more than the savings. Above that, sample the routine traffic but keep every error and every slow request. Only tail rules can do that, because a head sampler decides before it knows whether the request will fail. At very high volume, buffering every span in a Collector gets expensive too, and teams put a head sampler in front of the tail rules, accepting that it drops some errors. Most Laravel apps stay in the first two bands their whole life.
The NightOwl approach
NightOwl doesn't sample by default. It writes to your own PostgreSQL, so keeping everything costs database storage rather than a per-event fee, and the full dataset matters for debugging rare issues. If storage cost starts to matter, sampling happens in the Nightwatch config in your app, not in the NightOwl agent: the nightwatch.sampling.requests key, set with NIGHTWATCH_REQUEST_SAMPLE_RATE (commands, exceptions and scheduled tasks have their own rates).