Class: OpenTelemetry::SDK::Trace::Samplers::ConsistentProbabilityBased Private
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Trace::Samplers::ConsistentProbabilityBased
- Includes:
- ConsistentProbabilityTraceState
- Defined in:
- lib/opentelemetry/sdk/trace/samplers/consistent_probability_based.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Implements consistent sampling based on a probability.
Instance Attribute Summary collapse
- #description ⇒ Object readonly private
Instance Method Summary collapse
- #==(other) ⇒ Object private
-
#initialize(probability) ⇒ ConsistentProbabilityBased
constructor
private
A new instance of ConsistentProbabilityBased.
- #should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ Boolean private
Constructor Details
#initialize(probability) ⇒ ConsistentProbabilityBased
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ConsistentProbabilityBased.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_based.rb', line 19 def initialize(probability) if probability < 2e-62 @p_floor = 63 @p_ceil = @p_ceil_probability = 0 @description = 'ConsistentProbabilityBased{0}' return end @p_floor = (Math.frexp(probability)[1] - 1).abs @p_ceil = @p_floor - 1 floor = Math.ldexp(1.0, -@p_floor) ceil = Math.ldexp(1.0, -@p_ceil) @p_ceil_probability = (probability - floor) / (ceil - floor) @description = format('ConsistentProbabilityBased{%.6f}', probability) end |
Instance Attribute Details
#description ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_based.rb', line 17 def description @description end |
Instance Method Details
#==(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_based.rb', line 35 def ==(other) @description == other.description end |
#should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_based.rb', line 42 def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context p = probabilistic_p tracestate = parent_span_context.tracestate parse_ot_vendor_tag(tracestate) do |_, r, rest| if r.nil? || r > 62 OpenTelemetry.logger.debug("ConsistentProbabilitySampler: potentially inconsistent trace detected - r: #{r.inspect}") if parent_span_context.valid? r = generate_r(trace_id) end if p <= r Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: update_tracestate(tracestate, p, r, rest)) else Result.new(decision: Decision::DROP, tracestate: update_tracestate(tracestate, nil, r, rest)) end end end |