Class: Datadog::Tracing::Sampling::Span::Matcher
- Inherits:
-
Object
- Object
- Datadog::Tracing::Sampling::Span::Matcher
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name_pattern: MATCH_ALL_PATTERN, service_pattern: MATCH_ALL_PATTERN) ⇒ Matcher
constructor
Matches span name and service to their respective patterns provided.
-
#match?(span) ⇒ Boolean
Returns ‘true` if the span conforms to the configured patterns, `false` otherwise.
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:
-
‘?`: matches exactly one of any character.
-
‘*`: 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.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/datadog/tracing/sampling/span/matcher.rb', line 11 def name @name end |
#service ⇒ Object (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
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 |