Sampling
Sampling is a process that restricts the amount of traces that are generated by a system. The Ruby SDK offers several head samplers.
Default behavior¶
By default, all spans are sampled, and thus, 100% of traces are sampled. If you do not need to manage data volume, don't bother setting a sampler.
Specifically, the default sampler is a composite of ParentBased and ALWAYS_ON that ensures the root span in a trace is always sampled, and that all child spans respect use their parent's sampling flag to make a sampling decision. This guarantees that all spans in a trace are sampled by default.
TraceIDRatioBased Sampler¶
The most common head sampler to use is the TraceIdRatioBased sampler. It deterministically samples a percentage of traces that you pass in as a parameter.
Environment Variables¶
You can configure a TraceIdRatioBased
sampler with environment variables:
This tells the SDK to sample spans such that only 10% of traces get exported.
Configuration in Code¶
Although it is possible to configure a TraceIdRatioBased
sampler in code, it's
not recommended. Doing so requires you to manually set up a Tracer Provider with
all the right configuration options, which is hard to get right compared to just
using OpenTelemetry::SDK.configure
.