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 collapse

MATCH_ALL =

Returns ‘true` for case equality (===) with any object

Class.new do
  # DEV: A class that implements `#===` is ~20% faster than
  # DEV: a `Proc` that always returns `true`.
  def ===(other)
    true
  end
end.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SimpleMatcher.

Parameters:

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

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

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

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

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

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



40
41
42
43
44
45
46
# File 'lib/datadog/tracing/sampling/matcher.rb', line 40

def initialize(name: MATCH_ALL, service: MATCH_ALL, resource: MATCH_ALL, tags: {})
  super()
  @name = name
  @service = service
  @resource = resource
  @tags = tags
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/datadog/tracing/sampling/matcher.rb', line 32

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource.



32
33
34
# File 'lib/datadog/tracing/sampling/matcher.rb', line 32

def resource
  @resource
end

#serviceObject (readonly)

Returns the value of attribute service.



32
33
34
# File 'lib/datadog/tracing/sampling/matcher.rb', line 32

def service
  @service
end

#tagsObject (readonly)

Returns the value of attribute tags.



32
33
34
# File 'lib/datadog/tracing/sampling/matcher.rb', line 32

def tags
  @tags
end

Instance Method Details

#match?(trace) ⇒ Boolean

Returns:

  • (Boolean)


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

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