Class: Datadog::Tracing::Sampling::Span::Rule
- Inherits:
-
Object
- Object
- Datadog::Tracing::Sampling::Span::Rule
- Defined in:
- lib/datadog/tracing/sampling/span/rule.rb
Overview
Span sampling rule that applies a sampling rate if the span matches the provided Matcher. Additionally, a rate limiter is also applied.
If a span does not conform to the matcher, no changes are made.
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#rate_limit ⇒ Object
readonly
Returns the value of attribute rate_limit.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(matcher, sample_rate: Span::Ext::DEFAULT_SAMPLE_RATE, rate_limit: Span::Ext::DEFAULT_MAX_PER_SECOND) ⇒ Rule
constructor
Creates a new span sampling rule.
-
#sample!(trace_op, span_op) ⇒ :kept, ...
This method should only be invoked for spans that are part of a trace that has been dropped by trace-level sampling.
Constructor Details
#initialize(matcher, sample_rate: Span::Ext::DEFAULT_SAMPLE_RATE, rate_limit: Span::Ext::DEFAULT_MAX_PER_SECOND) ⇒ Rule
Creates a new span sampling rule.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/datadog/tracing/sampling/span/rule.rb', line 22 def initialize( matcher, sample_rate: Span::Ext::DEFAULT_SAMPLE_RATE, rate_limit: Span::Ext::DEFAULT_MAX_PER_SECOND ) @matcher = matcher @sample_rate = sample_rate @rate_limit = rate_limit @sampler = Sampling::RateSampler.new(sample_rate) @rate_limiter = Core::TokenBucket.new(rate_limit) end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
15 16 17 |
# File 'lib/datadog/tracing/sampling/span/rule.rb', line 15 def matcher @matcher end |
#rate_limit ⇒ Object (readonly)
Returns the value of attribute rate_limit.
15 16 17 |
# File 'lib/datadog/tracing/sampling/span/rule.rb', line 15 def rate_limit @rate_limit end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
15 16 17 |
# File 'lib/datadog/tracing/sampling/span/rule.rb', line 15 def sample_rate @sample_rate end |
Instance Method Details
#==(other) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/datadog/tracing/sampling/span/rule.rb', line 66 def ==(other) return super unless other.is_a?(Rule) matcher == other.matcher && sample_rate == other.sample_rate && rate_limit == other.rate_limit end |
#sample!(trace_op, span_op) ⇒ :kept, ...
This method should only be invoked for spans that are part of a trace that has been dropped by trace-level sampling. Invoking it for other spans will cause incorrect sampling metrics to be reported by the Datadog App.
Returns true if the provided span is sampled. If the span is dropped due to sampling rate or rate limiting, it returns false.
Returns nil if the span did not meet the matching criteria by the provided matcher.
This method modifies the span if it matches the provided matcher.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/datadog/tracing/sampling/span/rule.rb', line 53 def sample!(trace_op, span_op) return :not_matched unless @matcher.match?(span_op) if @rate_limiter.allow? && @sampler.sample!(trace_op) span_op.set_metric(Span::Ext::TAG_MECHANISM, Sampling::Ext::Mechanism::SPAN_SAMPLING_RATE) span_op.set_metric(Span::Ext::TAG_RULE_RATE, @sample_rate) span_op.set_metric(Span::Ext::TAG_MAX_PER_SECOND, @rate_limit) :kept else :rejected end end |