Module: Datadog::Contrib::Extensions::Configuration::Settings

Defined in:
lib/ddtrace/contrib/extensions.rb

Overview

Extensions for Datadog::Configuration::Settings

Constant Summary collapse

InvalidIntegrationError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#[](integration_name, key = :default) ⇒ Datadog::Contrib::Configuration::Settings

For the provided integration_name, resolves a matching configuration for the provided integration from an integration-specific key.

How the matching is performed is integration-specific.

Parameters:

  • integration_name (Symbol)

    the integration name

  • key (Object) (defaults to: :default)

    the integration-specific lookup key

Returns:



104
105
106
107
# File 'lib/ddtrace/contrib/extensions.rb', line 104

def [](integration_name, key = :default)
  integration = fetch_integration(integration_name)
  integration.resolve(key) unless integration.nil?
end

#configuration(integration_name, describes = nil) ⇒ Datadog::Contrib::Configuration::Settings

For the provided integration_name, retrieves a configuration previously stored by #instrument. Specifically, describes should be the same value provided in the describes: option for #instrument.

If no describes value is provided, the default configuration is returned.

Parameters:

  • integration_name (Symbol)

    the integration name

  • describes (Object) (defaults to: nil)

    the previously configured describes: object. If nil, fetches the default configuration

Returns:



119
120
121
122
# File 'lib/ddtrace/contrib/extensions.rb', line 119

def configuration(integration_name, describes = nil)
  integration = fetch_integration(integration_name)
  integration.configuration(describes) unless integration.nil?
end

#fetch_integration(name) ⇒ Object



153
154
155
156
# File 'lib/ddtrace/contrib/extensions.rb', line 153

def fetch_integration(name)
  Contrib::REGISTRY[name] ||
    raise(InvalidIntegrationError, "'#{name}' is not a valid integration.")
end

#instrument(integration_name, options = {}, &block) ⇒ Object Also known as: use



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/ddtrace/contrib/extensions.rb', line 124

def instrument(integration_name, options = {}, &block)
  integration = fetch_integration(integration_name)

  unless integration.nil? || !integration.default_configuration.enabled
    configuration_name = options[:describes] || :default
    filtered_options = options.reject { |k, _v| k == :describes }
    integration.configure(configuration_name, filtered_options, &block)
    instrumented_integrations[integration_name] = integration

    # Add to activation list
    integrations_pending_activation << integration
  end
end

#instrumented_integrationsObject



144
145
146
# File 'lib/ddtrace/contrib/extensions.rb', line 144

def instrumented_integrations
  @instrumented_integrations ||= {}
end

#integrations_pending_activationObject



140
141
142
# File 'lib/ddtrace/contrib/extensions.rb', line 140

def integrations_pending_activation
  @integrations_pending_activation ||= Set.new
end

#reduce_log_verbosityObject



162
163
164
# File 'lib/ddtrace/contrib/extensions.rb', line 162

def reduce_log_verbosity
  @reduce_verbosity ||= true
end

#reduce_verbosity?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/ddtrace/contrib/extensions.rb', line 158

def reduce_verbosity?
  defined?(@reduce_verbosity) ? @reduce_verbosity : false
end

#registryObject

Deprecated.

Use Datadog.registry instead

The registry only holds declarative constant values and cannot be modified. This option is a no-op and will be removed in the future.



81
82
83
84
85
# File 'lib/ddtrace/contrib/extensions.rb', line 81

def registry
  Datadog.logger.warn('Deprecated access to `Datadog.configuration.registry`, use `Datadog.registry` instead.' \
                      '`Datadog.configuration.registry` will be removed in a future version.')
  Contrib::REGISTRY
end

#registry=(_arg) ⇒ Object

Deprecated.

The registry is now a global constant, and can't be overwritten.

The registry only holds declarative constant values and cannot be modified. This option is a no-op and will be removed in the future.



91
92
93
94
# File 'lib/ddtrace/contrib/extensions.rb', line 91

def registry=(_arg)
  Datadog.logger.warn('Setting a custom registry is no longer supported and was ignored. ' \
                      'Remove this assignment from your configuration to stop seeing this warning.')
end

#reset!Object



148
149
150
151
# File 'lib/ddtrace/contrib/extensions.rb', line 148

def reset!
  instrumented_integrations.clear
  super
end