Class: Jaeger::Samplers::Probabilistic
- Inherits:
-
Object
- Object
- Jaeger::Samplers::Probabilistic
- Defined in:
- lib/jaeger/samplers/probabilistic.rb
Overview
Probabilistic sampler
Sample a portion of traces using trace_id as the random decision
Instance Attribute Summary collapse
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
Instance Method Summary collapse
-
#initialize(rate: 0.001) ⇒ Probabilistic
constructor
A new instance of Probabilistic.
- #sample(trace_id:) ⇒ Object
- #update(rate:) ⇒ Object
Constructor Details
#initialize(rate: 0.001) ⇒ Probabilistic
Returns a new instance of Probabilistic.
11 12 13 |
# File 'lib/jaeger/samplers/probabilistic.rb', line 11 def initialize(rate: 0.001) update(rate: rate) end |
Instance Attribute Details
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
9 10 11 |
# File 'lib/jaeger/samplers/probabilistic.rb', line 9 def rate @rate end |
Instance Method Details
#sample(trace_id:) ⇒ Object
33 34 35 |
# File 'lib/jaeger/samplers/probabilistic.rb', line 33 def sample(trace_id:, **) [@boundary >= trace_id, @tags] end |
#update(rate:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jaeger/samplers/probabilistic.rb', line 15 def update(rate:) if rate < 0.0 || rate > 1.0 raise "Sampling rate must be between 0.0 and 1.0, got #{rate.inspect}" end new_boundary = TraceId::TRACE_ID_UPPER_BOUND * rate return false if @boundary == new_boundary @rate = rate @boundary = TraceId::TRACE_ID_UPPER_BOUND * rate @tags = { 'sampler.type' => 'probabilistic', 'sampler.param' => rate } true end |