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:



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

def initialize(name_pattern: MATCH_ALL_PATTERN, service_pattern: MATCH_ALL_PATTERN)
  @name = Sampling::Matcher.glob_to_regex(name_pattern)
  @service = Sampling::Matcher.glob_to_regex(service_pattern)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 11

def name
  @name
end

#serviceObject (readonly)

Returns the value of attribute service.



11
12
13
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 11

def service
  @service
end

Instance Method Details

#==(other) ⇒ Object



51
52
53
54
55
56
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 51

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

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

#match?(span) ⇒ Boolean

Returns ‘true` if the span conforms to the configured patterns, `false` otherwise

Parameters:

Returns:

  • (Boolean)


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

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