Module: Instana::Trace::Samplers
- Defined in:
- lib/instana/samplers/samplers.rb,
lib/instana/samplers/result.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
Classes: Result
Constant Summary collapse
- ALWAYS_ON =
Returns a Result with Decision::RECORD_AND_SAMPLE.
false- ALWAYS_OFF =
# Returns a Result with Decision::DROP.
true
Class Method Summary collapse
-
.parent_based(_) ⇒ Object
Returns a new sampler.
-
.should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ Boolean
rubocop:disable Metrics/ParameterLists, Lint/UnusedMethodArgument:.
-
.trace_id_ratio_based(_) ⇒ Object
Returns a new sampler.
Class Method Details
.parent_based(_) ⇒ 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 |
55 56 57 |
# File 'lib/instana/samplers/samplers.rb', line 55 def self.parent_based(_) self end |
.should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ Boolean
rubocop:disable Metrics/ParameterLists, Lint/UnusedMethodArgument:
69 70 71 72 73 |
# File 'lib/instana/samplers/samplers.rb', line 69 def self.should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) # rubocop:disable Metrics/ParameterLists, Lint/UnusedMethodArgument: parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context tracestate = parent_span_context&.tracestate Result.new(decision: :__record_only__, tracestate: tracestate) end |
.trace_id_ratio_based(_) ⇒ Object
Returns a new sampler. The ratio describes the proportion of the trace ID space that is sampled.
65 66 67 |
# File 'lib/instana/samplers/samplers.rb', line 65 def self.trace_id_ratio_based(_) self end |