Class: Datadog::Tracing::Sampling::Matcher Abstract
- Inherits:
-
Object
- Object
- Datadog::Tracing::Sampling::Matcher
- Defined in:
- lib/datadog/tracing/sampling/matcher.rb
Overview
This class is abstract.
Checks if a trace conforms to a matching criteria.
Direct Known Subclasses
Constant Summary collapse
- MATCH_ALL_PATTERN =
Pattern that matches any string
'*'
- MATCH_ALL =
Returns ‘true` for any input
Class.new do def match?(_other) true end def inspect "MATCH_ALL:Matcher('*')" end end.new
Class Method Summary collapse
-
.glob_to_regex(glob) ⇒ #match?(String)
Converts a glob pattern String to a case-insensitive String matcher object.
Instance Method Summary collapse
-
#match?(trace) ⇒ Boolean
Returns ‘true` if the trace should conforms to this rule, `false` otherwise.
Class Method Details
.glob_to_regex(glob) ⇒ #match?(String)
Converts a glob pattern String to a case-insensitive String matcher object. The match object will only return ‘true` if it matches the complete String.
The following special characters are supported:
-
‘?` matches any single character
-
‘*` matches any substring
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/datadog/tracing/sampling/matcher.rb', line 29 def self.glob_to_regex(glob) # Optimization for match-all case return MATCH_ALL if /\A\*+\z/.match?(glob) # Ensure no undesired characters are treated as regex. glob = Regexp.quote(glob) # Our valid special characters, `?` and `*`, were just escaped # by `Regexp.quote` above. We need to unescape them: glob.gsub!('\?', '.') # Any single character glob.gsub!('\*', '.*') # Any substring # Patterns have to match the whole input string glob = "\\A#{glob}\\z" Regexp.new(glob, Regexp::IGNORECASE) end |
Instance Method Details
#match?(trace) ⇒ Boolean
Returns ‘true` if the trace should conforms to this rule, `false` otherwise
16 17 18 |
# File 'lib/datadog/tracing/sampling/matcher.rb', line 16 def match?(trace) raise NotImplementedError end |