instrument_sampler_parent_based (instrument v1.0.0)

View Source

Parent-based sampler that defers to parent's sampling decision.

This sampler makes decisions based on the parent span's sampling state: - If parent is sampled, child is sampled - If parent is not sampled, child is not sampled - If no parent (root span), delegates to a configurable root sampler

Configuration

- root: Sampler for root spans (default: instrument_sampler_always_on) - root_config: Configuration for root sampler (default: #{}) - remote_parent_sampled: Sampler when remote parent is sampled (default: always_on) - remote_parent_not_sampled: Sampler when remote parent is not sampled (default: always_off) - local_parent_sampled: Sampler when local parent is sampled (default: always_on) - local_parent_not_sampled: Sampler when local parent is not sampled (default: always_off)

Example

  instrument_sampler:set_sampler(instrument_sampler_parent_based, #{
    root => instrument_sampler_probability,
    root_config => #{ratio => 0.1}
  }).

Summary

Functions

get_description(Config)

-spec get_description(Config :: map()) -> binary().

Returns the sampler description.

should_sample(Config, TraceId, SpanName, SpanKind, Attributes, Links, ParentCtx)

-spec should_sample(Config :: map(),
                    TraceId :: binary(),
                    SpanName :: binary(),
                    SpanKind :: atom(),
                    Attributes :: map(),
                    Links :: list(),
                    ParentCtx ::
                        #span_ctx{trace_id :: <<_:128>> | undefined,
                                  span_id :: <<_:64>> | undefined,
                                  trace_flags :: 0 | 1,
                                  trace_state :: [{binary(), binary()}],
                                  is_remote :: boolean()} |
                        undefined) ->
                       #sampling_result{decision :: drop | record_only | record_and_sample,
                                        attributes :: map(),
                                        trace_state :: [{binary(), binary()}]}.

Samples based on parent context.