Class: Datadog::Tracing::Sampling::Span::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/sampling/span/matcher.rb

Overview

Checks if a span conforms to a matching criteria.

Constant Summary collapse

MATCH_ALL_PATTERN =

Pattern that matches any string

'*'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_pattern: MATCH_ALL_PATTERN, service_pattern: MATCH_ALL_PATTERN) ⇒ Matcher

Matches span name and service to their respective patterns provided.

The patterns are Strings with two special characters available:

  1. ‘?`: matches exactly one of any character.

  2. ‘*`: matches a substring of any size, including zero.

These patterns can occur any point of the string, any number of times.

Both Datadog::Tracing::SpanOperation#name and Datadog::Tracing::SpanOperation#service must match the provided patterns.

The whole String has to match the provided patterns: providing a pattern that matches a portion of the provided String is not considered a match.

Examples:

web-*

`'web-*'` will match any string starting with `web-`.

cache-?

`'cache-?'` will match any string starting with `database-` followed by exactly one character.

Parameters:



33
34
35
36
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 33

def initialize(name_pattern: MATCH_ALL_PATTERN, service_pattern: MATCH_ALL_PATTERN)
  @name = pattern_to_regex(name_pattern)
  @service = pattern_to_regex(service_pattern)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 9

def name
  @name
end

#serviceObject (readonly)

Returns the value of attribute service.



9
10
11
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 9

def service
  @service
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
62
63
64
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 59

def ==(other)
  return super unless other.is_a?(Matcher)

  name == other.name &&
    service == other.service
end

#match?(span) ⇒ Boolean

DEV: Remove when support for Ruby 2.3 and older is removed.

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 47

def match?(span)
  # Matching is performed at the end of the lifecycle of a Span,
  # thus both `name` and `service` are guaranteed to be not `nil`.
  @name.match?(span.name) && @service.match?(span.service)
end