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
Constant Summary collapse
- PROVENANCE_LOCAL =
:local- PROVENANCE_REMOTE_USER =
:customer- PROVENANCE_REMOTE_DYNAMIC =
:dynamic
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#provenance ⇒ Object
readonly
Returns the value of attribute provenance.
-
#sampler ⇒ Object
readonly
Returns the value of attribute sampler.
Instance Method Summary collapse
-
#initialize(matcher, sampler, provenance) ⇒ Rule
constructor
A new instance of Rule.
-
#match?(trace) ⇒ Boolean, NilClass
Evaluates if the provided
traceconforms to thematcher. -
#sample!(trace) ⇒ Boolean
Returns
trueif the provided trace should be kept. -
#sample_rate(trace) ⇒ Float?
The sampling rate, if this sampler has such concept.
Constructor Details
#initialize(matcher, sampler, provenance) ⇒ Rule
Returns a new instance of Rule.
22 23 24 25 26 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 22 def initialize(matcher, sampler, provenance) @matcher = matcher @sampler = sampler @provenance = provenance end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
18 19 20 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 18 def matcher @matcher end |
#provenance ⇒ Object (readonly)
Returns the value of attribute provenance.
18 19 20 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 18 def provenance @provenance end |
#sampler ⇒ Object (readonly)
Returns the value of attribute sampler.
18 19 20 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 18 def sampler @sampler end |
Instance Method Details
#match?(trace) ⇒ Boolean, NilClass
Evaluates if the provided trace conforms to the matcher.
33 34 35 36 37 38 39 40 41 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 33 def match?(trace) @matcher.match?(trace) rescue => e Datadog.logger.error( "Matcher failed. Cause: #{e.class.name} #{e.} Source: #{Array(e.backtrace).first}" ) Datadog::Core::Telemetry::Logger.report(e, description: 'Matcher failed') nil end |
#sample!(trace) ⇒ Boolean
Returns true if the provided trace should be kept. Otherwise, false.
This method may modify the trace, in case changes are necessary based on the sampling decision.
44 45 46 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 44 def sample!(trace) @sampler.sample!(trace) end |
#sample_rate(trace) ⇒ Float?
The sampling rate, if this sampler has such concept. Otherwise, nil.
49 50 51 |
# File 'lib/datadog/tracing/sampling/rule.rb', line 49 def sample_rate(trace) @sampler.sample_rate(trace) end |