Class: Datadog::RateSampler
Overview
RateSampler is based on a sample rate.
Constant Summary collapse
- KNUTH_FACTOR =
1111111111111111111- SAMPLE_RATE_METRIC_KEY =
'_sample_rate'.freeze()
Instance Attribute Summary collapse
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#initialize(sample_rate = 1.0) ⇒ RateSampler
constructor
Initialize a RateSampler.
- #sample(span) ⇒ Object
Constructor Details
#initialize(sample_rate = 1.0) ⇒ RateSampler
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.
30 31 32 33 34 35 36 37 |
# File 'lib/ddtrace/sampler.rb', line 30 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 |
Instance Attribute Details
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
21 22 23 |
# File 'lib/ddtrace/sampler.rb', line 21 def sample_rate @sample_rate end |
Instance Method Details
#sample(span) ⇒ Object
44 45 46 47 |
# File 'lib/ddtrace/sampler.rb', line 44 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 |