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