Module: Datadog::Core::Configuration

Defined in:
lib/datadog/core/configuration.rb,
lib/datadog/core/configuration/ext.rb,
lib/datadog/core/configuration/base.rb,
lib/datadog/core/configuration/option.rb,
lib/datadog/core/configuration/options.rb,
lib/datadog/core/configuration/settings.rb,
lib/datadog/core/configuration/components.rb,
lib/datadog/core/configuration/option_definition.rb,
lib/datadog/core/configuration/agent_settings_resolver.rb

Overview

Configuration provides a unique access point for configurations

Defined Under Namespace

Modules: Base, Ext, Options Classes: AgentSettingsResolver, Components, Option, OptionDefinition, Settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configurationDatadog::Core::Configuration::Settings

Current Datadog configuration.

Access to non-global configuration will raise an error.

To modify the configuration, use #configure.



49
50
51
# File 'lib/datadog/core/configuration.rb', line 49

def configuration
  @configuration ||= Settings.new
end

Instance Method Details

#configuration_for(target, option = nil) ⇒ Object

Get configuration changes applied only to a specific Ruby object, via #configure_onto. An example of an object with specific configuration:

“‘ client = Net::HTTP.new(host, port) Datadog.configure_onto(client, service_name: ’api-requests’, split_by_domain: true) config = Datadog.configuration_for(client) config # => ‘api-requests’ config # => true “‘

Parameters:

  • target (Object)

    the object to receive configuration options

  • option (Object) (defaults to: nil)

    an option to retrieve from the object configuration



145
146
147
148
149
150
# File 'lib/datadog/core/configuration.rb', line 145

def configuration_for(target, option = nil)
  pin = Pin.get_from(target)
  return pin unless option

  pin[option] if pin
end

#configure {|c| ... } ⇒ Object

Apply global configuration changes to ‘Datadog`. An example of a #configure call:

“‘ Datadog.configure do |c|

c.service = 'my-service'
c.env = 'staging'
# c.diagnostics.debug = true # Enables debug output

end “‘

See Settings for all available options, defaults, and available environment variables for configuration.

Only permits access to global configuration settings; others will raise an error. If you wish to configure a setting for a specific Datadog component (e.g. Tracing), use the corresponding ‘Datadog::COMPONENT.configure` method instead.

Because many configuration changes require restarting internal components, invoking #configure is the only safe way to change ‘Datadog` configuration.

Successive calls to #configure maintain the previous configuration values: configuration is additive between #configure calls.

The yielded configuration ‘c` comes pre-populated from environment variables, if any are applicable.

Yield Parameters:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/datadog/core/configuration.rb', line 80

def configure
  configuration = self.configuration
  yield(configuration)

  safely_synchronize do |write_components|
    write_components.call(
      if components?
        replace_components!(configuration, @components)
      else
        build_components(configuration)
      end
    )
  end

  configuration
end

#configure_onto(target, **opts) ⇒ Object

Apply configuration changes only to a specific Ruby object.

Certain integrations or Datadog features may use these settings to customize behavior for this object.

An example of a #configure_onto call:

“‘ client = Net::HTTP.new(host, port) Datadog.configure_onto(client, service_name: ’api-requests’, split_by_domain: true) “‘

In this example, it will configure the ‘client` object with custom options `service_name: ’api-requests’, split_by_domain: true`. The ‘Net::HTTP` integration will then use these customized options when the `client` is used, whereas other clients will use the `service_name: ’http-requests’‘ configuration provided to the `Datadog.configure` call block.

#configure_onto is used to separate cases where spans generated by certain objects require exceptional options.

The configuration keyword arguments provided should match well known options defined in the integration or feature that would use them.

For example, for ‘Datadog.configure_onto(redis_client, **opts)`, `opts` can be any of the options in the Redis Tracing::Contrib::Redis::Configuration::Settings class.

Parameters:

  • target (Object)

    the object to receive configuration options

  • opts (Hash)

    keyword arguments respective to the integration this object belongs to



127
128
129
# File 'lib/datadog/core/configuration.rb', line 127

def configure_onto(target, **opts)
  Pin.set_on(target, **opts)
end

#health_metricsObject

Internal Statsd metrics collection.

The list of metrics collected can be found in Diagnostics::Ext::Health::Metrics.



156
157
158
# File 'lib/datadog/core/configuration.rb', line 156

def health_metrics
  components.health_metrics
end

#loggerObject



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/datadog/core/configuration.rb', line 160

def logger
  # avoid initializing components if they didn't already exist
  current_components = components(allow_initialization: false)

  if current_components
    @temp_logger = nil
    current_components.logger
  else
    logger_without_components
  end
end

#shutdown!Object

Gracefully shuts down all components.

Components will still respond to method calls as usual, but might not internally perform their work after shutdown.

This avoids errors being raised across the host application during shutdown, while allowing for graceful decommission of resources.

Components won’t be automatically reinitialized after a shutdown.



181
182
183
184
185
# File 'lib/datadog/core/configuration.rb', line 181

def shutdown!
  safely_synchronize do
    @components.shutdown! if components?
  end
end