Class: Datadog::Tracing::Sampling::Rule

Inherits:
Object
  • Object
show all
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

SimpleRule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, sampler) ⇒ Rule

Returns a new instance of Rule.

Parameters:

  • matcher (Matcher)

    A matcher to verify trace conformity against

  • sampler (Sampler)

    A sampler to be consulted on a positive match



20
21
22
23
# File 'lib/datadog/tracing/sampling/rule.rb', line 20

def initialize(matcher, sampler)
  @matcher = matcher
  @sampler = sampler
end

Instance Attribute Details

#matcherObject (readonly)

Returns the value of attribute matcher.



16
17
18
# File 'lib/datadog/tracing/sampling/rule.rb', line 16

def matcher
  @matcher
end

#samplerObject (readonly)

Returns the value of attribute sampler.



16
17
18
# File 'lib/datadog/tracing/sampling/rule.rb', line 16

def sampler
  @sampler
end

Instance Method Details

#match?(trace) ⇒ Boolean, NilClass

Evaluates if the provided trace conforms to the matcher.

Parameters:

Returns:

  • (Boolean)

    whether this rules applies to the trace

  • (NilClass)

    if the matcher fails errs during evaluation



30
31
32
33
34
35
36
37
# File 'lib/datadog/tracing/sampling/rule.rb', line 30

def match?(trace)
  @matcher.match?(trace)
rescue => e
  Datadog.logger.error(
    "Matcher failed. Cause: #{e.class.name} #{e.message} 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.

Parameters:

Returns:

  • (Boolean)

    should this trace be kept?



40
41
42
# File 'lib/datadog/tracing/sampling/rule.rb', line 40

def sample?(trace)
  @sampler.sample?(trace)
end

#sample_rate(trace) ⇒ Float?

The sampling rate, if this sampler has such concept. Otherwise, nil.

Parameters:

Returns:

  • (Float, nil)

    sampling ratio between 0.0 and 1.0 (inclusive), or nil if not applicable



45
46
47
# File 'lib/datadog/tracing/sampling/rule.rb', line 45

def sample_rate(trace)
  @sampler.sample_rate(trace)
end