Class: Datadog::Tracing::Contrib::Configuration::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/contrib/configuration/resolver.rb

Overview

Resolves an integration-specific matcher to an associated object.

Integrations that perform any configuration matching based on patterns might want to override this class to provide richer matching. For example, match configuration based on: HTTP request parameters, request headers, async queue name.

When overriding this class, for simple use cases, only overriding ‘#parse_matcher` might suffice. See `#parse_matcher`’s documentation for more information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResolver

Returns a new instance of Resolver.



22
23
24
# File 'lib/datadog/tracing/contrib/configuration/resolver.rb', line 22

def initialize
  @configurations = {}
end

Instance Attribute Details

#configurationsObject (readonly)

Returns the value of attribute configurations.



20
21
22
# File 'lib/datadog/tracing/contrib/configuration/resolver.rb', line 20

def configurations
  @configurations
end

Instance Method Details

#add(matcher, value) ⇒ Object

Adds a new ‘matcher`, associating with it a `value`.

This ‘value` is returned when `#resolve` is called with a matching value for this matcher. When multiple matchers would match, `#resolve` returns the latest added one.

The ‘matcher` can be transformed internally by the `#parse_matcher` method before being stored.

The ‘value` can also be retrieved by calling `#get` with the same `matcher` added by this method.

Parameters:

  • matcher (Object)

    integration-specific matcher

  • value (Object)

    arbitrary value to be associated with ‘matcher`



41
42
43
# File 'lib/datadog/tracing/contrib/configuration/resolver.rb', line 41

def add(matcher, value)
  @configurations[parse_matcher(matcher)] = value
end

#get(matcher) ⇒ Object

Retrieves the stored value for a ‘matcher` previously stored by `#add`.

Parameters:

  • matcher (Object)

    integration-specific matcher

Returns:

  • (Object)

    previously stored ‘value` from `#add`, or `nil` if not found



50
51
52
# File 'lib/datadog/tracing/contrib/configuration/resolver.rb', line 50

def get(matcher)
  @configurations[parse_matcher(matcher)]
end

#resolve(value) ⇒ Object

Matches an arbitrary value against the configured matchers previously set with ‘#add`.

If multiple matchers would match, returns the latest one.

Parameters:

  • value (Object)

    integration-specific value

Returns:

  • (Object)

    matching ‘value` configured at `#add`, or `nil` if none match



61
62
63
# File 'lib/datadog/tracing/contrib/configuration/resolver.rb', line 61

def resolve(value)
  @configurations[value]
end