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
-
#configuration_for(target, option = nil) ⇒ Object
Get configuration changes applied only to a specific Ruby object, via #configure_onto.
-
#configure {|c| ... } ⇒ Object
Apply global configuration changes to ‘Datadog`.
-
#configure_onto(target, **opts) ⇒ Object
Apply configuration changes only to a specific Ruby object.
-
#health_metrics ⇒ Object
Internal Statsd metrics collection.
- #logger ⇒ Object
-
#shutdown! ⇒ Object
Gracefully shuts down all components.
Instance Attribute Details
#configuration ⇒ Object
|
# File 'lib/datadog/core/configuration.rb', line 42
|
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 “‘
148 149 150 151 152 153 |
# File 'lib/datadog/core/configuration.rb', line 148 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/datadog/core/configuration.rb', line 83 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.
130 131 132 |
# File 'lib/datadog/core/configuration.rb', line 130 def configure_onto(target, **opts) Pin.set_on(target, **opts) end |
#health_metrics ⇒ Object
Internal Statsd metrics collection.
The list of metrics collected can be found in Diagnostics::Ext::Health::Metrics.
159 160 161 |
# File 'lib/datadog/core/configuration.rb', line 159 def health_metrics components.health_metrics end |
#logger ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/datadog/core/configuration.rb', line 163 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.
184 185 186 187 188 |
# File 'lib/datadog/core/configuration.rb', line 184 def shutdown! safely_synchronize do @components.shutdown! if components? end end |