Sha256: d6148a43c2228c7a42b90b70b8178755ecab30fd1c7f62bb91c97217a8909a20

Contents?: true

Size: 455 Bytes

Versions: 31

Compression:

Stored size: 455 Bytes

Contents

# frozen_string_literal: true

require "digest"

module Honeycomb
  ##
  # Provides a should_sample method which can be used for deterministic
  # sampling
  #
  module DeterministicSampler
    MAX_INT32 = 2**32 - 1

    def should_sample(rate, value)
      return true if rate == 1

      upper_bound = MAX_INT32 / rate
      digest = Digest::SHA1.digest(value)[0, 4]
      value = digest.unpack("I!>").first
      value <= upper_bound
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
honeycomb-beeline-2.11.1.pre.dev lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.11.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.10.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.9.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.8.2 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.8.1 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.8.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.7.1 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.7.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.6.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.5.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.4.2 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.4.1 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.4.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.3.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.2.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.1.2 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.1.1 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.1.0 lib/honeycomb/deterministic_sampler.rb
honeycomb-beeline-2.0.0 lib/honeycomb/deterministic_sampler.rb