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

Defined in:
lib/datadog/tracing/contrib/extensions.rb

Overview

Extensions for Datadog::Core::Configuration::Settings

Constant Summary collapse

InvalidIntegrationError =
Class.new(StandardError)
INSTRUMENTED_INTEGRATIONS_LOCK =

Used to avoid concurrency issues between registering integrations (e.g. mutation) and reporting the current integrations for logging/debugging/telemetry purposes (e.g. iteration) in the @instrumented_integrations hash.

See https://github.com/DataDog/dd-trace-rb/issues/2851 for details on the original issue.

Mutex.new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/datadog/tracing/contrib/extensions.rb', line 120

def self.included(base)
  base.class_eval do
    settings :contrib do
      # Key-value map for explicitly re-mapping peer.service values
      #
      # @default `DD_TRACE_PEER_SERVICE_MAPPING` environment variable converted to hash
      # @return [Hash]
      option :peer_service_mapping do |o|
        o.env Tracing::Configuration::Ext::SpanAttributeSchema::ENV_PEER_SERVICE_MAPPING
        o.type :hash
        o.default({})
      end

      # Enables population of default in the `peer.service` span tag.
      # Explicitly setting the `peer.service` for an integration will
      # still be honored with this option disabled.
      #
      # Also when disabled, other peer service related configurations have no effect.
      #
      # @default `DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED` environment variable, otherwise `false`
      # @return [Boolean]
      option :peer_service_defaults do |o|
        o.env Tracing::Configuration::Ext::SpanAttributeSchema::ENV_PEER_SERVICE_DEFAULTS_ENABLED
        o.type :bool
        o.default false
      end

      # Global service name behavior
      settings :global_default_service_name do
        # Overrides default service name to global service name
        #
        # Allows for usage of v1 service name changes without
        # being forced to update schema versions
        #
        # @default `DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED` environment variable, otherwise `false`
        # @return [Boolean]
        option :enabled do |o|
          o.env Tracing::Configuration::Ext::SpanAttributeSchema::ENV_GLOBAL_DEFAULT_SERVICE_NAME_ENABLED
          o.type :bool
          o.default false
        end
      end
    end
  end
end

Instance Method Details

#[](integration_name, key = :default) ⇒ Datadog::Tracing::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.

Examples:

Datadog.configuration.tracing[:integration_name]
Datadog.configuration.tracing[:integration_name][:sub_configuration]

Parameters:

  • integration_name (Symbol)

    the integration name

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

    the integration-specific lookup key

Returns:



209
210
211
212
# File 'lib/datadog/tracing/contrib/extensions.rb', line 209

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

#ignore_integration_load_errors=(value) ⇒ Object



243
244
245
# File 'lib/datadog/tracing/contrib/extensions.rb', line 243

def ignore_integration_load_errors=(value)
  @ignore_integration_load_errors = value
end

#instrument(integration_name, options = {}, &block) ⇒ Datadog::Tracing::Contrib::Integration

Applies instrumentation for the provided integration_name.

Options may be provided, that are specific to that instrumentation. See the instrumentation's settings file for a list of available options.

Examples:

Datadog.configure { |c| c.tracing.instrument :integration_name }
Datadog.configure { |c| c.tracing.instrument :integration_name, option_key: :option_value }

Parameters:

  • integration_name (Symbol)

    the integration name

  • options (Hash) (defaults to: {})

    the integration-specific configuration settings

Returns:



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/datadog/tracing/contrib/extensions.rb', line 178

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_LOCK.synchronize do
      @instrumented_integrations ||= {}
      @instrumented_integrations[integration_name] = integration
    end

    # Add to activation list
    integrations_pending_activation << integration
  end

  integration
end