Class: Datadog::Sampling::Rule

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ddtrace/sampling/rule.rb

Overview

Sampling rule that dictates if a span 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 span conformity against

  • sampler (Sampler)

    A sampler to be consulted on a positive match



19
20
21
22
# File 'lib/ddtrace/sampling/rule.rb', line 19

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

Instance Attribute Details

#matcherObject (readonly)

Returns the value of attribute matcher.



15
16
17
# File 'lib/ddtrace/sampling/rule.rb', line 15

def matcher
  @matcher
end

#samplerObject (readonly)

Returns the value of attribute sampler.



15
16
17
# File 'lib/ddtrace/sampling/rule.rb', line 15

def sampler
  @sampler
end

Instance Method Details

#match?(span) ⇒ Boolean, NilClass

Evaluates if the provided span conforms to the matcher.

Parameters:

Returns:

  • (Boolean)

    whether this rules applies to the span

  • (NilClass)

    if the matcher fails errs during evaluation



29
30
31
32
33
34
# File 'lib/ddtrace/sampling/rule.rb', line 29

def match?(span)
  @matcher.match?(span)
rescue => e
  Datadog.logger.error("Matcher failed. Cause: #{e.message} Source: #{Array(e.backtrace).first}")
  nil
end