NAME

OpenTelemetry::SDK::Trace::Sampler - The abstract interface for a sampler object

SYNOPSIS

use Object::Pad;
class My::Sampler :does(OpenTelemetry::SDK::Trace::Sampler) {
    field $description :param :reader;
    method should_sample (%args) { ... }
}

my $sampler = My::Sampler->new;

my $result = $sampler->should_sample( ... );

if ( $result->sampled ) {
    # this span should be sampled
}

DESCRIPTION

This role describes the interface that all sampler classes should implement.

REQUIRED METHODS

description

$string = $sampler->description;

Returns a string that can be used to identify the current configuration of the sampler. This string may appear in debug pages and logs. Standard samplers have a PascalCased name for the sampler, and additional configuration between braces ({...}), which can be used as a guide.

should_sample

$result = $sampler->should_sample(
    context    => $context,
    trace_id   => $trace_id,
    kind       => $span_kind,
    name       => $span_name,
    attributes => \%attributes,
    links      => \@links,
);

Returns a sampling decision for a span to be created. Takes a set of named parameters, all of which are required:

context

A OpenTelemetry::Context object that holds the parent span. The OpenTelemetry::Trace::SpanContext may be invalid to indicate a root span.

trace_id

The binary trace ID of the span to be created. This must match the trace ID of the parent's span context if it is valid.

name

The name of the span to be created.

kind

The kind of the span to be created.

attributes

The initial set of attributes of the span to be created.

A set of links that will be associated with the span to be created.

SEE ALSO

OpenTelemetry::Attributes
OpenTelemetry::Context
OpenTelemetry::SDK::Trace::Sampler::Result
OpenTelemetry::Trace::SpanContext
Span kind constants
The specification for a sampler's should_sample method

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by José Joaquín Atria.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.