Class: Datadog::Core::Configuration::Settings
- Inherits:
-
Object
- Object
- Datadog::Core::Configuration::Settings
- Extended by:
- Tracing::Configuration::Settings
- Includes:
- Base
- Defined in:
- lib/datadog/core/configuration/settings.rb
Overview
Global configuration settings for the Datadog library. rubocop:disable Metrics/BlockLength
Instance Method Summary collapse
-
#api_key ⇒ String?
Datadog API key.
-
#env ⇒ String?
The ‘env` tag in Datadog.
-
#service ⇒ String
The ‘service` tag in Datadog.
-
#site ⇒ String?
The Datadog site host to send data to.
-
#tags ⇒ Hash<String,String>
Default tags.
-
#time_now_provider ⇒ Proc<Time>
The time provider used by Datadog.
-
#version ⇒ String?
The ‘version` tag in Datadog.
Methods included from Tracing::Configuration::Settings
Methods included from Base
Instance Method Details
#api_key ⇒ String?
Datadog API key.
For internal use only.
81 82 83 84 |
# File 'lib/datadog/core/configuration/settings.rb', line 81 option :api_key do |o| o.default { ENV.fetch(Core::Environment::Ext::ENV_API_KEY, nil) } o.lazy end |
#env ⇒ String?
The ‘env` tag in Datadog. Use it to separate out your staging, development, and production environments.
156 157 158 159 160 |
# File 'lib/datadog/core/configuration/settings.rb', line 156 option :env do |o| # NOTE: env also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. o.default { ENV.fetch(Core::Environment::Ext::ENV_ENVIRONMENT, nil) } o.lazy end |
#service ⇒ String
The ‘service` tag in Datadog. Use it to group related traces into a service.
355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/datadog/core/configuration/settings.rb', line 355 option :service do |o| # NOTE: service also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. o.default { ENV.fetch(Core::Environment::Ext::ENV_SERVICE, Core::Environment::Ext::FALLBACK_SERVICE_NAME) } o.lazy # There's a few cases where we don't want to use the fallback service name, so this helper allows us to get a # nil instead so that one can do # nice_service_name = Datadog.configuration.service_without_fallback || nice_service_name_default o.helper(:service_without_fallback) do service_name = service service_name unless service_name.equal?(Core::Environment::Ext::FALLBACK_SERVICE_NAME) end end |
#site ⇒ String?
The Datadog site host to send data to. By default, data is sent to the Datadog US site: ‘app.datadoghq.com`.
If your organization is on another site, you must update this value to the new site.
For internal use only.
379 380 381 382 |
# File 'lib/datadog/core/configuration/settings.rb', line 379 option :site do |o| o.default { ENV.fetch(Core::Environment::Ext::ENV_SITE, nil) } o.lazy end |
#tags ⇒ Hash<String,String>
Default tags
These tags are used by all Datadog products, when applicable. e.g. trace spans, profiles, etc.
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/datadog/core/configuration/settings.rb', line 390 option :tags do |o| o.default do = {} # Parse tags from environment env_to_list(Core::Environment::Ext::ENV_TAGS, comma_separated_only: false).each do |tag| key, value = tag.split(':', 2) [key] = value if value && !value.empty? end # Override tags if defined [Core::Environment::Ext::TAG_ENV] = env unless env.nil? [Core::Environment::Ext::TAG_VERSION] = version unless version.nil? end o.setter do |new_value, old_value| # Coerce keys to strings = new_value.collect { |k, v| [k.to_s, v] }.to_h # Cross-populate tag values with other settings if env.nil? && .key?(Core::Environment::Ext::TAG_ENV) self.env = [Core::Environment::Ext::TAG_ENV] end if version.nil? && .key?(Core::Environment::Ext::TAG_VERSION) self.version = [Core::Environment::Ext::TAG_VERSION] end if service_without_fallback.nil? && .key?(Core::Environment::Ext::TAG_SERVICE) self.service = [Core::Environment::Ext::TAG_SERVICE] end # Merge with previous tags (old_value || {}).merge() end o.lazy end |
#time_now_provider ⇒ Proc<Time>
The time provider used by Datadog. It must respect the interface of [Time](ruby-doc.org/core-3.0.1/Time.html).
When testing, it can be helpful to use a different time provider.
For [Timecop](rubygems.org/gems/timecop), for example, ‘->{ Time.now_without_mock_time }` allows Datadog features to use the real wall time when time is frozen.
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/datadog/core/configuration/settings.rb', line 440 option :time_now_provider do |o| o.default { ::Time.now } o.on_set do |time_provider| Core::Utils::Time.now_provider = time_provider end o.resetter do |_value| # TODO: Resetter needs access to the default value # TODO: to help reduce duplication. -> { ::Time.now }.tap do |default| Core::Utils::Time.now_provider = default end end end |
#version ⇒ String?
The ‘version` tag in Datadog. Use it to enable [Deployment Tracking](docs.datadoghq.com/tracing/deployment_tracking/).
460 461 462 463 464 |
# File 'lib/datadog/core/configuration/settings.rb', line 460 option :version do |o| # NOTE: version also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. o.default { ENV.fetch(Core::Environment::Ext::ENV_VERSION, nil) } o.lazy end |