Sampling at the application level via the SDK
Allowing applications to decide what to sample, provides a great amount of flexibility to application developers and operators, as these applications are the source of the tracing data. Samplers can be configured in OpenTelemetry as a property of the tracer provider. In the following code, a configure_tracer
method configures the OpenTelemetry tracing pipeline and receives Sampler
as a method argument. This method is used to obtain three different tracers, each with its own sampling configuration:
ALWAYS_ON
: A sampler that always samples.ALWAYS_OFF
: A sampler that never samples.TraceIdRatioBased
: A probability sampler, which in the example is configured to sample traces 50% of the time.
The code then produces a separate trace using each tracer to demonstrate how sampling impacts the output generated by ConsoleSpanExporter
:
sample.py
from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk...