Class: Datadog::Tracing::Sampling::Rule
- Inherits:
-
Object
- Object
- Datadog::Tracing::Sampling::Rule
- Defined in:
- lib/datadog/tracing/sampling/rule.rb
Overview
Sampling rule that dictates if a trace matches a specific criteria and what sampling strategy to apply in case of a positive match.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#sampler ⇒ Object
readonly
Returns the value of attribute sampler.
Instance Method Summary collapse
-
#initialize(matcher, sampler) ⇒ Rule
constructor
A new instance of Rule.
-
#match?(trace) ⇒ Boolean, NilClass
Evaluates if the provided ‘trace` conforms to the `matcher`.
-
#sample?(trace) ⇒ Boolean
Returns ‘true` if the provided trace should be kept.
-
#sample_rate(trace) ⇒ Float?
The sampling rate, if this sampler has such concept.
Constructor Details
#initialize(matcher, sampler) ⇒ Rule
Returns a new instance of Rule.
18 19 20 21 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 18 def initialize(matcher, sampler) @matcher = matcher @sampler = sampler end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
14 15 16 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 14 def matcher @matcher end |
#sampler ⇒ Object (readonly)
Returns the value of attribute sampler.
14 15 16 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 14 def sampler @sampler end |
Instance Method Details
#match?(trace) ⇒ Boolean, NilClass
Evaluates if the provided ‘trace` conforms to the `matcher`.
28 29 30 31 32 33 34 35 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 28 def match?(trace) @matcher.match?(trace) rescue => e Datadog.logger.error( "Matcher failed. Cause: #{e.class.name} #{e.} Source: #{Array(e.backtrace).first}" ) nil end |
#sample?(trace) ⇒ Boolean
Returns ‘true` if the provided trace should be kept. Otherwise, `false`.
This method *must not* modify the ‘trace`.
38 39 40 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 38 def sample?(trace) @sampler.sample?(trace) end |
#sample_rate(trace) ⇒ Float?
The sampling rate, if this sampler has such concept. Otherwise, ‘nil`.
43 44 45 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 43 def sample_rate(trace) @sampler.sample_rate(trace) end |