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(decision: Decision::RECORD_AND_SAMPLE, description: 'AlwaysOnSampler')
- ALWAYS_OFF =
Returns a Result with Decision::DROP.
ConstantSampler.new(decision: Decision::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 |
67 68 69 70 71 72 73 74 75 |
# File 'lib/opentelemetry/sdk/trace/samplers.rb', line 67 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.
83 84 85 86 87 |
# File 'lib/opentelemetry/sdk/trace/samplers.rb', line 83 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 |