Module: OpenTelemetry::SDK::Trace::Samplers
- Defined in:
- lib/opentelemetry/sdk/trace/samplers.rb,
lib/opentelemetry/sdk/trace/samplers/result.rb,
lib/opentelemetry/sdk/trace/samplers/decision.rb,
lib/opentelemetry/sdk/trace/samplers/parent_or_else.rb,
lib/opentelemetry/sdk/trace/samplers/constant_sampler.rb,
lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb
Overview
The Samplers module contains the sampling logic for OpenTelemetry. The reference implementation provides a ProbabilitySampler, ALWAYS_ON, ALWAYS_OFF, and ParentOrElse.
Custom samplers can be provided by SDK users. The required interface is:
should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) -> Result description -> String
Where:
Defined Under Namespace
Modules: Decision Classes: ConstantSampler, ParentOrElse, ProbabilitySampler, Result
Constant Summary collapse
- ALWAYS_ON =
Returns a Result with Decision::RECORD_AND_SAMPLED.
ConstantSampler.new(result: RECORD_AND_SAMPLED, description: 'AlwaysOnSampler')
- ALWAYS_OFF =
Returns a Result with Decision::NOT_RECORD.
ConstantSampler.new(result: NOT_RECORD, description: 'AlwaysOffSampler')
Class Method Summary collapse
-
.parent_or_else(delegate_sampler) ⇒ Object
Returns a new sampler.
-
.probability(probability, ignore_parent: false, apply_probability_to: :root_spans_and_remote_parent) ⇒ Object
Returns a new sampler.
Class Method Details
.parent_or_else(delegate_sampler) ⇒ Object
Returns a new sampler. It either respects the parent span's sampling decision or delegates to delegate_sampler for root spans.
59 60 61 |
# File 'lib/opentelemetry/sdk/trace/samplers.rb', line 59 def self.parent_or_else(delegate_sampler) ParentOrElse.new(delegate_sampler) end |
.probability(probability, ignore_parent: false, apply_probability_to: :root_spans_and_remote_parent) ⇒ Object
Returns a new sampler. The probability of sampling a trace is equal to that of the specified probability.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/opentelemetry/sdk/trace/samplers.rb', line 76 def self.probability(probability, ignore_parent: false, apply_probability_to: :root_spans_and_remote_parent) raise ArgumentError, 'probability must be in range [0.0, 1.0]' unless (0.0..1.0).include?(probability) raise ArgumentError, 'apply_probability_to' unless APPLY_PROBABILITY_TO_SYMBOLS.include?(apply_probability_to) ProbabilitySampler.new(probability, ignore_parent: ignore_parent, apply_to_remote_parent: apply_probability_to != :root_spans, apply_to_all_spans: apply_probability_to == :all_spans) end |