View Source otel_sampler behaviour (opentelemetry v1.3.0)

A sampler is a function run on each started span that returns whether to record and propagate, only record or not record the span.

Link to this section Summary

Link to this section Types

-type builtin_sampler() ::
    always_on | always_off |
    {trace_id_ratio_based, float()} |
    {parent_based,
     #{remote_parent_sampled => sampler_spec(),
       remote_parent_not_sampled => sampler_spec(),
       local_parent_sampled => sampler_spec(),
       local_parent_not_sampled => sampler_spec(),
       root => sampler_spec()}}.
-type description() :: unicode:unicode_binary().
-type sampler_config() :: term().
-type sampler_opts() :: term().
-type sampler_spec() :: builtin_sampler() | {module(), sampler_opts()}.
-type sampling_decision() :: drop | record_only | record_and_sample.
-type sampling_result() ::
    {sampling_decision(), opentelemetry:attributes_map(), opentelemetry:tracestate()}.
-opaque t()

Link to this section Callbacks

-callback description(sampler_config()) -> description().
-callback setup(sampler_opts()) -> sampler_config().
-callback should_sample(otel_ctx:t(),
              opentelemetry:trace_id(),
              otel_links:t(),
              opentelemetry:span_name(),
              opentelemetry:span_kind(),
              opentelemetry:attributes_map(),
              sampler_config()) ->
                 sampling_result().

Link to this section Functions

-spec description(t()) -> description().
-spec new(sampler_spec()) -> t().
Link to this function

should_sample(_, Ctx, TraceId, Links, SpanName, Kind, Attributes)

View Source
-spec should_sample(t(),
              otel_ctx:t(),
              opentelemetry:trace_id(),
              otel_links:t(),
              opentelemetry:span_name(),
              opentelemetry:span_kind(),
              opentelemetry:attributes_map()) ->
                 sampling_result().