Class: Datadog::Tracing::Sampling::SimpleMatcher

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

Overview

A Sampling::Matcher that supports matching a trace by trace name and/or service name.

Constant Summary

Constants inherited from Matcher

Matcher::MATCH_ALL, Matcher::MATCH_ALL_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

glob_to_regex

Constructor Details

#initialize(name: MATCH_ALL_PATTERN, service: MATCH_ALL_PATTERN, resource: MATCH_ALL_PATTERN, tags: {}) ⇒ SimpleMatcher

Returns a new instance of SimpleMatcher.

Parameters:

  • name (String, Regexp, Proc) (defaults to: MATCH_ALL_PATTERN)

    Matcher for case equality (===) with the trace name, defaults to always match

  • service (String, Regexp, Proc) (defaults to: MATCH_ALL_PATTERN)

    Matcher for case equality (===) with the service name, defaults to always match

  • resource (String, Regexp, Proc) (defaults to: MATCH_ALL_PATTERN)

    Matcher for case equality (===) with the resource name, defaults to always match



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/datadog/tracing/sampling/matcher.rb', line 70

def initialize(
  name: MATCH_ALL_PATTERN,
  service: MATCH_ALL_PATTERN,
  resource: MATCH_ALL_PATTERN,
  tags: {}
)
  super()

  name = Matcher.glob_to_regex(name)
  service = Matcher.glob_to_regex(service)
  resource = Matcher.glob_to_regex(resource)
  tags = tags.transform_values { |matcher| Matcher.glob_to_regex(matcher) }

  @name = name || Datadog::Tracing::Sampling::Matcher::MATCH_ALL
  @service = service || Datadog::Tracing::Sampling::Matcher::MATCH_ALL
  @resource = resource || Datadog::Tracing::Sampling::Matcher::MATCH_ALL
  @tags = tags
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

#serviceObject (readonly)

Returns the value of attribute service.



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

def service
  @service
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

Instance Method Details

#match?(trace) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'lib/datadog/tracing/sampling/matcher.rb', line 89

def match?(trace)
  @name.match?(trace.name) &&
    @service.match?(trace.service) &&
    @resource.match?(trace.resource) &&
    tags_match?(trace)
end