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

Inherits:
Object
  • Object
show all
Extended by:
AIGuard::Configuration::Settings, OpenFeature::Configuration::Settings, OpenTelemetry::Configuration::Settings, Tracing::Configuration::Settings
Includes:
Base
Defined in:
lib/datadog/core/configuration/settings.rb

Overview

Global configuration settings for the Datadog library. standard:disable Metrics/BlockLength

Constant Summary

Constants included from OpenFeature::Configuration::Settings

OpenFeature::Configuration::Settings::DEFAULT_INITIALIZATION_TIMEOUT_MS, OpenFeature::Configuration::Settings::DEFAULT_POLL_INTERVAL_SECONDS, OpenFeature::Configuration::Settings::DEFAULT_REQUEST_TIMEOUT_SECONDS, OpenFeature::Configuration::Settings::MAX_INITIALIZATION_TIMEOUT_MS, OpenFeature::Configuration::Settings::MAX_REQUEST_TIMEOUT_SECONDS

Instance Method Summary collapse

Methods included from Tracing::Configuration::Settings

extended

Methods included from OpenTelemetry::Configuration::Settings

add_settings!, extended, headers_parser, normalize_protocol, normalize_temporality_preference

Methods included from AIGuard::Configuration::Settings

add_settings!, extended

Methods included from OpenFeature::Configuration::Settings

add_settings!, configure_integer_option, extended

Methods included from Base

included

Instance Method Details

#api_key ⇒ String?

Datadog API key.

For internal use only.

Returns:

  • (String, nil)


106
107
108
109
110
# File 'lib/datadog/core/configuration/settings.rb', line 106

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

#env ⇒ String?

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



169
170
171
172
173
# File 'lib/datadog/core/configuration/settings.rb', line 169

option :env do |o|
  o.type :string, nilable: true
  # 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

#experimental_propagate_process_tags_enabled ⇒ Boolean

Enable process tags propagation such that payloads like spans contain the process tag.

Returns:

  • (Boolean)


1096
1097
1098
1099
1100
# File 'lib/datadog/core/configuration/settings.rb', line 1096

option :experimental_propagate_process_tags_enabled do |o|
  o.env "DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED"
  o.default true
  o.type :bool
end

#hostname ⇒ String?

Override the hostname reported by this process. When report_hostname is enabled, sets the hostname on traces and the host.name resource attribute in OpenTelemetry.

Returns:

  • (String, nil)


180
181
182
183
# File 'lib/datadog/core/configuration/settings.rb', line 180

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

#service ⇒ String

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



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/datadog/core/configuration/settings.rb', line 701

option :service do |o|
  o.type :string, nilable: true

  # NOTE: service also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details.
  # Note: Alias (OTEL_SERVICE_NAME) defined in supported-configurations.json
  o.env Core::Environment::Ext::ENV_SERVICE
  o.default Core::Environment::Ext::FALLBACK_SERVICE_NAME

  o.after_set do |service_name|
    Core::Environment::Process.set_service(service_name, user_configured: !using_default?(:service))
  end

  # 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 using_default?(:service)
  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.



732
733
734
735
# File 'lib/datadog/core/configuration/settings.rb', line 732

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

#tags ⇒ Hash<String,String>

Default tags

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

Returns:

  • (Hash<String,String>)


743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'lib/datadog/core/configuration/settings.rb', line 743

option :tags do |o|
  o.type :hash, nilable: true
  # Note: Alias (OTEL_RESOURCE_ATTRIBUTES) defined in supported-configurations.json
  o.env Core::Environment::Ext::ENV_TAGS
  o.env_parser do |env_value|
    # Parses a string containing key-value pairs and returns a hash.
    # Key-value pairs are delimited by ':' OR `=`, and pairs are separated by whitespace, comma, OR BOTH.
    result = {}
    unless env_value.nil? || env_value.empty?
      # falling back to comma as separator
      sep = env_value.include?(",") ? "," : " "
      # split by separator
      env_value.split(sep).each do |tag|
        tag.strip!
        next if tag.empty?

        # tag by : or = (for OpenTelemetry)
        key, val = tag.split(/[:=]/, 2).map(&:strip)
        val ||= ""
        # maps OpenTelemetry semantic attributes to Datadog tags
        key = case key.downcase
        when "deployment.environment.name"
          result["env"] = val
          nil
        when "deployment.environment" then "env" unless result.key?("env")
        when "service.version" then "version"
        when "service.name" then "service"
        else key
        end
        result[key] = val unless key.nil? || key.empty?
      end
    end
    result
  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

#version ⇒ String?

The version tag in Datadog. Use it to enable Deployment Tracking.



851
852
853
854
855
# File 'lib/datadog/core/configuration/settings.rb', line 851

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