Class: Zipkin::Samplers::Probabilistic

Inherits:
Object
  • Object
show all
Defined in:
lib/zipkin/samplers/probabilistic.rb

Overview

Probabilistic sampler

Sample a portion of traces using trace_id as the random decision

Instance Method Summary collapse

Constructor Details

#initialize(rate: 0.001) ⇒ Probabilistic

Returns a new instance of Probabilistic.



9
10
11
12
13
14
# File 'lib/zipkin/samplers/probabilistic.rb', line 9

def initialize(rate: 0.001)
  if rate < 0.0 || rate > 1.0
    raise "Sampling rate must be between 0.0 and 1.0, got #{rate.inspect}"
  end
  @boundary = TraceId::TRACE_ID_UPPER_BOUND * rate
end

Instance Method Details

#sample?(trace_id:) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/zipkin/samplers/probabilistic.rb', line 16

def sample?(trace_id:, **)
  @boundary >= trace_id.to_i(16)
end