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_based.rb,
lib/opentelemetry/sdk/trace/samplers/constant_sampler.rb,
lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb
Overview
The Samplers module contains the sampling logic for OpenTelemetry. The reference implementation provides a TraceIdRatioBased, ALWAYS_ON, ALWAYS_OFF, and ParentBased.
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, ParentBased, Result, TraceIdRatioBased
Constant Summary collapse
- ALWAYS_ON =
Returns a Result with Decision::RECORD_AND_SAMPLE.
ConstantSampler.new(result: RECORD_AND_SAMPLE, description: 'AlwaysOnSampler')
- ALWAYS_OFF =
Returns a Result with Decision::DROP.
ConstantSampler.new(result: DROP, description: 'AlwaysOffSampler')
Class Method Summary collapse
-
.parent_based(root:, remote_parent_sampled: ALWAYS_ON, remote_parent_not_sampled: ALWAYS_OFF, local_parent_sampled: ALWAYS_ON, local_parent_not_sampled: ALWAYS_OFF) ⇒ Object
Returns a new sampler.
-
.trace_id_ratio_based(ratio) ⇒ Object
Returns a new sampler.
Class Method Details
.parent_based(root:, remote_parent_sampled: ALWAYS_ON, remote_parent_not_sampled: ALWAYS_OFF, local_parent_sampled: ALWAYS_ON, local_parent_not_sampled: ALWAYS_OFF) ⇒ Object
Returns a new sampler. It delegates to samplers according to the following rules:
| Parent | parent.remote? | parent.trace_flags.sampled? | Invoke sampler | |–|–|–|–| | absent | n/a | n/a | root | | present | true | true | remote_parent_sampled | | present | true | false | remote_parent_not_sampled | | present | false | true | local_parent_sampled | | present | false | false | local_parent_not_sampled |
74 75 76 77 78 79 80 81 82 |
# File 'lib/opentelemetry/sdk/trace/samplers.rb', line 74 def self.parent_based( root:, remote_parent_sampled: ALWAYS_ON, remote_parent_not_sampled: ALWAYS_OFF, local_parent_sampled: ALWAYS_ON, local_parent_not_sampled: ALWAYS_OFF ) ParentBased.new(root, remote_parent_sampled, remote_parent_not_sampled, local_parent_sampled, local_parent_not_sampled) end |
.trace_id_ratio_based(ratio) ⇒ Object
Returns a new sampler. The ratio describes the proportion of the trace ID space that is sampled.
90 91 92 93 94 |
# File 'lib/opentelemetry/sdk/trace/samplers.rb', line 90 def self.trace_id_ratio_based(ratio) raise ArgumentError, 'ratio must be in range [0.0, 1.0]' unless (0.0..1.0).include?(ratio) TraceIdRatioBased.new(ratio) end |