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 58 59 60 61 62 63 64 65 66 67 68 |
# 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 if parent_span_context.valid? tracestate = parent_span_context.tracestate parse_ot_vendor_tag(tracestate) do |_, in_r, rest| r = if in_r.nil? || in_r > 62 OpenTelemetry.logger.debug("ConsistentProbabilitySampler: potentially inconsistent trace detected - r: #{in_r.inspect}") generate_r(trace_id) else in_r 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 else r = generate_r(trace_id) if p <= r Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: new_tracestate(p: p, r: r)) else Result.new(decision: Decision::DROP, tracestate: new_tracestate(r: r)) end end end |