Sha256: 0f540c10f5bcacc8cfb8935cbbddc00e1501cf7fe90e63b0f38043a9372a2619
Contents?: true
Size: 1.43 KB
Versions: 14
Compression:
Stored size: 1.43 KB
Contents
module Datadog # \Sampler performs client-side trace sampling. class Sampler def sample(_span) raise NotImplementedError, 'samplers have to implement the sample() method' end end # \AllSampler samples all the traces. class AllSampler < Sampler def sample(span) span.sampled = true end end # \RateSampler is based on a sample rate. class RateSampler < Sampler KNUTH_FACTOR = 1111111111111111111 SAMPLE_RATE_METRIC_KEY = '_sample_rate'.freeze() attr_reader :sample_rate # Initialize a \RateSampler. # This sampler keeps a random subset of the traces. Its main purpose is to # reduce the instrumentation footprint. # # * +sample_rate+: the sample rate as a \Float between 0.0 and 1.0. 0.0 # means that no trace will be sampled; 1.0 means that all traces will be # sampled. def initialize(sample_rate = 1.0) unless sample_rate > 0.0 && sample_rate <= 1.0 Datadog::Tracer.log.error('sample rate is not between 0 and 1, disabling the sampler') sample_rate = 1.0 end self.sample_rate = sample_rate end def sample_rate=(sample_rate) @sample_rate = sample_rate @sampling_id_threshold = sample_rate * Span::MAX_ID end def sample(span) span.sampled = ((span.trace_id * KNUTH_FACTOR) % Datadog::Span::MAX_ID) <= @sampling_id_threshold span.set_metric(SAMPLE_RATE_METRIC_KEY, @sample_rate) end end end
Version data entries
14 entries across 14 versions & 2 rubygems