Class: Datadog::Core::Configuration::Settings

Inherits:
Object
  • Object
show all
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

Methods included from Tracing::Configuration::Settings

extended

Methods included from Base

included

Instance Method Details

#api_keyString?

Datadog API key.

For internal use only.

Returns:

  • (String, nil)


82
83
84
85
# File 'lib/datadog/core/configuration/settings.rb', line 82

option :api_key do |o|
  o.type :string, nilable: true
  o.env Core::Environment::Ext::ENV_API_KEY
end

#envString?

The ‘env` tag in Datadog. Use it to separate out your staging, development, and production environments.



158
159
160
161
162
163
164
# File 'lib/datadog/core/configuration/settings.rb', line 158

option :env do |o|
  # DEV-2.0: Remove this conversion for symbol.
  o.setter { |v| v.to_s if v }

  # NOTE: env also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details.
  o.env Core::Environment::Ext::ENV_ENVIRONMENT
end

#serviceString

The ‘service` tag in Datadog. Use it to group related traces into a service.



570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/datadog/core/configuration/settings.rb', line 570

option :service do |o|
  # DEV-2.0: Remove this conversion for symbol.
  o.setter { |v| v.to_s if v }

  # NOTE: service also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details.
  o.env Core::Environment::Ext::ENV_SERVICE
  o.default Core::Environment::Ext::FALLBACK_SERVICE_NAME

  # 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

#siteString?

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.



597
598
599
600
# File 'lib/datadog/core/configuration/settings.rb', line 597

option :site do |o|
  o.type :string, nilable: true
  o.env Core::Environment::Ext::ENV_SITE
end

#tagsHash<String,String>

Default tags

These tags are used by all Datadog products, when applicable. e.g. trace spans, profiles, etc.

Returns:

  • (Hash<String,String>)


608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/datadog/core/configuration/settings.rb', line 608

option :tags do |o|
  o.type :hash, nilable: true
  o.env Core::Environment::Ext::ENV_TAGS
  o.env_parser do |env_value|
    values = if env_value.include?(',')
               env_value.split(',')
             else
               env_value.split(' ') # rubocop:disable Style/RedundantArgument
             end

    values.map! do |v|
      v.gsub!(/\A[\s,]*|[\s,]*\Z/, '')

      v.empty? ? nil : v
    end

    values.compact!
    values.each_with_object({}) do |tag, tags|
      key, value = tag.split(':', 2)
      tags[key] = value if value && !value.empty?
    end
  end
  o.setter do |new_value, old_value|
    raw_tags = new_value || {}

    env_value = env
    version_value = version
    service_name = service_without_fallback

    # Override tags if defined
    raw_tags[Core::Environment::Ext::TAG_ENV] = env_value unless env_value.nil?
    raw_tags[Core::Environment::Ext::TAG_VERSION] = version_value unless version_value.nil?

    # Coerce keys to strings
    string_tags = raw_tags.collect { |k, v| [k.to_s, v] }.to_h

    # Cross-populate tag values with other settings
    if env_value.nil? && string_tags.key?(Core::Environment::Ext::TAG_ENV)
      self.env = string_tags[Core::Environment::Ext::TAG_ENV]
    end

    if version_value.nil? && string_tags.key?(Core::Environment::Ext::TAG_VERSION)
      self.version = string_tags[Core::Environment::Ext::TAG_VERSION]
    end

    if service_name.nil? && string_tags.key?(Core::Environment::Ext::TAG_SERVICE)
      self.service = string_tags[Core::Environment::Ext::TAG_SERVICE]
    end

    # Merge with previous tags
    (old_value || {}).merge(string_tags)
  end
end

#time_now_providerProc<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.

Returns:

  • (Proc<Time>)


671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# File 'lib/datadog/core/configuration/settings.rb', line 671

option :time_now_provider do |o|
  o.default_proc { ::Time.now }
  o.type :proc

  o.after_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

#versionString?

The ‘version` tag in Datadog. Use it to enable [Deployment Tracking](docs.datadoghq.com/tracing/deployment_tracking/).



692
693
694
695
696
# File 'lib/datadog/core/configuration/settings.rb', line 692

option :version do |o|
  # NOTE: version also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details.
  o.type :string, nilable: true
  o.env Core::Environment::Ext::ENV_VERSION
end