Class Sampler

Inheritance Relationships

Derived Types

Class Documentation

class Sampler

The Sampler interface allows users to create custom samplers which will return a SamplingResult based on information that is typically available just before the Span was created.

Subclassed by opentelemetry::sdk::trace::AlwaysOffSampler, opentelemetry::sdk::trace::AlwaysOnSampler, opentelemetry::sdk::trace::ParentBasedSampler, opentelemetry::sdk::trace::TraceIdRatioBasedSampler

Public Functions

virtual ~Sampler() = default
virtual SamplingResult ShouldSample(const opentelemetry::trace::SpanContext &parent_context, opentelemetry::trace::TraceId trace_id, nostd::string_view name, opentelemetry::trace::SpanKind span_kind, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept = 0

Called during Span creation to make a sampling decision.

Since

0.1.0

Parameters
  • parent_context – a const reference to the SpanContext of a parent Span. An invalid SpanContext if this is a root span.

  • trace_id – the TraceId for the new Span. This will be identical to that in the parentContext, unless this is a root span.

  • name – the name of the new Span.

  • spanKind – the opentelemetry::trace::SpanKind of the Span.

  • attributes – list of AttributeValue with their keys.

  • links – Collection of links that will be associated with the Span to be created.

Returns

sampling result whether span should be sampled or not.

virtual nostd::string_view GetDescription() const noexcept = 0

Returns the sampler name or short description with the configuration. This may be displayed on debug pages or in the logs.

Returns

the description of this Sampler.