Module: Honeycomb::DeterministicSampler
- Included in:
- Span
- Defined in:
- lib/honeycomb/deterministic_sampler.rb
Overview
Provides a should_sample method which can be used for deterministic sampling
Constant Summary collapse
- MAX_INT32 =
2**32 - 1
Instance Method Summary collapse
Instance Method Details
#should_sample(rate, value) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/honeycomb/deterministic_sampler.rb', line 13 def should_sample(rate, value) return true if rate == 1 upper_bound = MAX_INT32 / rate digest = Digest::SHA1.digest(value)[0, 4] value = digest.unpack1("I!>") value <= upper_bound end |