From c9f4ec8ba1df6d70948bda166e2ab783f823d864 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Thu, 29 Jun 2023 13:58:52 +0100 Subject: [PATCH] Add env_var and deprecated_env_var configuration options --- lib/datadog/appsec/configuration/settings.rb | 52 +++--- lib/datadog/ci/configuration/settings.rb | 7 +- .../cucumber/configuration/settings.rb | 9 +- .../contrib/rspec/configuration/settings.rb | 8 +- lib/datadog/core/configuration/option.rb | 15 +- .../core/configuration/option_definition.rb | 18 ++ lib/datadog/core/configuration/settings.rb | 169 ++++++++++++------ .../core/environment/variable_helpers.rb | 87 +++------ lib/datadog/profiling/http_transport.rb | 2 +- lib/datadog/tracing/configuration/settings.rb | 115 ++++++------ .../action_cable/configuration/settings.rb | 18 +- .../action_mailer/configuration/settings.rb | 18 +- .../action_pack/configuration/settings.rb | 18 +- .../action_view/configuration/settings.rb | 18 +- .../active_job/configuration/settings.rb | 18 +- .../configuration/settings.rb | 18 +- .../active_record/configuration/settings.rb | 19 +- .../active_support/configuration/settings.rb | 19 +- .../contrib/aws/configuration/settings.rb | 24 ++- .../concurrent_ruby/configuration/settings.rb | 6 +- .../contrib/dalli/configuration/settings.rb | 24 ++- .../delayed_job/configuration/settings.rb | 18 +- .../elasticsearch/configuration/settings.rb | 24 ++- .../contrib/ethon/configuration/settings.rb | 24 ++- .../contrib/excon/configuration/settings.rb | 24 ++- .../contrib/faraday/configuration/settings.rb | 24 ++- .../contrib/grape/configuration/settings.rb | 18 +- .../contrib/graphql/configuration/settings.rb | 18 +- .../contrib/grpc/configuration/settings.rb | 24 ++- .../contrib/hanami/configuration/settings.rb | 6 +- .../contrib/http/configuration/settings.rb | 30 ++-- .../httpclient/configuration/settings.rb | 30 ++-- .../contrib/httprb/configuration/settings.rb | 30 ++-- .../contrib/kafka/configuration/settings.rb | 18 +- .../contrib/lograge/configuration/settings.rb | 6 +- .../contrib/mongodb/configuration/settings.rb | 24 ++- .../contrib/mysql2/configuration/settings.rb | 33 ++-- .../contrib/pg/configuration/settings.rb | 33 ++-- .../contrib/presto/configuration/settings.rb | 24 ++- .../contrib/qless/configuration/settings.rb | 24 ++- .../contrib/que/configuration/settings.rb | 30 ++-- .../contrib/racecar/configuration/settings.rb | 19 +- .../contrib/rack/configuration/settings.rb | 18 +- .../contrib/rails/configuration/settings.rb | 20 ++- .../contrib/rake/configuration/settings.rb | 20 ++- .../contrib/redis/configuration/settings.rb | 30 ++-- .../contrib/resque/configuration/settings.rb | 18 +- .../rest_client/configuration/settings.rb | 24 ++- .../contrib/roda/configuration/settings.rb | 18 +- .../semantic_logger/configuration/settings.rb | 6 +- .../contrib/sequel/configuration/settings.rb | 18 +- .../shoryuken/configuration/settings.rb | 18 +- .../contrib/sidekiq/configuration/settings.rb | 24 ++- .../contrib/sinatra/configuration/settings.rb | 18 +- .../sneakers/configuration/settings.rb | 18 +- .../contrib/stripe/configuration/settings.rb | 18 +- .../sucker_punch/configuration/settings.rb | 18 +- .../core/environment/variable_helpers.rbs | 8 +- .../core/configuration/settings_spec.rb | 4 +- .../core/environment/variable_helpers_spec.rb | 26 +-- 60 files changed, 911 insertions(+), 576 deletions(-) diff --git a/lib/datadog/appsec/configuration/settings.rb b/lib/datadog/appsec/configuration/settings.rb index f978cca35e3..c3e7da929c9 100644 --- a/lib/datadog/appsec/configuration/settings.rb +++ b/lib/datadog/appsec/configuration/settings.rb @@ -33,11 +33,11 @@ def self.add_settings!(base) base.class_eval do settings :appsec do option :enabled do |o| - o.default { env_to_bool('DD_APPSEC_ENABLED', DEFAULT_APPSEC_ENABLED) } - o.setter do |v| - v ? true : false + o.env_var 'DD_APPSEC_ENABLED' + o.default DEFAULT_APPSEC_ENABLED + o.setter do |value| + val_to_bool(value) end - o.lazy end define_method(:instrument) do |integration_name| @@ -54,7 +54,8 @@ def self.add_settings!(base) end option :ruleset do |o| - o.default { ENV.fetch('DD_APPSEC_RULES', DEFAULT_APPSEC_RULESET) } + o.env_var 'DD_APPSEC_RULES' + o.default { DEFAULT_APPSEC_RULESET } o.lazy end @@ -69,7 +70,8 @@ def self.add_settings!(base) end option :waf_timeout do |o| - o.default { ENV.fetch('DD_APPSEC_WAF_TIMEOUT', DEFAULT_APPSEC_WAF_TIMEOUT) } # us + o.env_var 'DD_APPSEC_WAF_TIMEOUT' + o.default { DEFAULT_APPSEC_WAF_TIMEOUT } # us o.setter do |v| Datadog::Core::Utils::Duration.call(v.to_s, base: :us) end @@ -77,41 +79,36 @@ def self.add_settings!(base) end option :waf_debug do |o| - o.default { env_to_bool('DD_APPSEC_WAF_DEBUG', DEFAULT_APPSEC_WAF_DEBUG) } - o.setter do |v| - v ? true : false + o.env_var 'DD_APPSEC_WAF_DEBUG' + o.default DEFAULT_APPSEC_WAF_DEBUG + o.setter do |value| + val_to_bool(value) end - o.lazy end option :trace_rate_limit do |o| - o.default { env_to_int('DD_APPSEC_TRACE_RATE_LIMIT', DEFAULT_APPSEC_TRACE_RATE_LIMIT) } # trace/s - o.lazy + o.env_var 'DD_APPSEC_TRACE_RATE_LIMIT' + o.setter do |value| + val_to_int(value, DEFAULT_APPSEC_TRACE_RATE_LIMIT) + end # trace/s end option :obfuscator_key_regex do |o| - o.default { ENV.fetch('DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP', DEFAULT_OBFUSCATOR_KEY_REGEX) } + o.env_var 'DD_APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP' + o.default { DEFAULT_OBFUSCATOR_KEY_REGEX } o.lazy end option :obfuscator_value_regex do |o| - o.default do - ENV.fetch( - 'DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP', - DEFAULT_OBFUSCATOR_VALUE_REGEX - ) - end + o.env_var 'DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP' + o.default { DEFAULT_OBFUSCATOR_VALUE_REGEX } o.lazy end settings :track_user_events do option :enabled do |o| - o.default do - ENV.fetch( - 'DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING', - DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_ENABLED - ) - end + o.env_var 'DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING' + o.default { DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_ENABLED } o.setter do |v| if v v.to_s != 'disabled' @@ -123,9 +120,8 @@ def self.add_settings!(base) end option :mode do |o| - o.default do - ENV.fetch('DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING', DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_MODE) - end + o.env_var 'DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING' + o.default { DEFAULT_APPSEC_AUTOMATED_TRACK_USER_EVENTS_MODE } o.setter do |v| string_value = v.to_s if APPSEC_VALID_TRACK_USER_EVENTS_MODE.include?(string_value) diff --git a/lib/datadog/ci/configuration/settings.rb b/lib/datadog/ci/configuration/settings.rb index acc46a53dc1..16681cdbd01 100644 --- a/lib/datadog/ci/configuration/settings.rb +++ b/lib/datadog/ci/configuration/settings.rb @@ -16,8 +16,11 @@ def self.add_settings!(base) base.class_eval do settings :ci do option :enabled do |o| - o.default { env_to_bool(CI::Ext::Settings::ENV_MODE_ENABLED, false) } - o.lazy + o.env_var CI::Ext::Settings::ENV_MODE_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end end # DEV: Alias to Datadog::Tracing::Contrib::Extensions::Configuration::Settings#instrument. diff --git a/lib/datadog/ci/contrib/cucumber/configuration/settings.rb b/lib/datadog/ci/contrib/cucumber/configuration/settings.rb index b23ea565378..ecdf03456a0 100644 --- a/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +++ b/lib/datadog/ci/contrib/cucumber/configuration/settings.rb @@ -12,7 +12,10 @@ module Configuration # TODO: mark as `@public_api` when GA class Settings < Datadog::Tracing::Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end o.lazy end @@ -22,8 +25,8 @@ class Settings < Datadog::Tracing::Contrib::Configuration::Settings end option :operation_name do |o| - o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME } - o.lazy + o.env_var Ext::ENV_OPERATION_NAME + o.default Ext::OPERATION_NAME end end end diff --git a/lib/datadog/ci/contrib/rspec/configuration/settings.rb b/lib/datadog/ci/contrib/rspec/configuration/settings.rb index d537aadff38..b03816ca71e 100644 --- a/lib/datadog/ci/contrib/rspec/configuration/settings.rb +++ b/lib/datadog/ci/contrib/rspec/configuration/settings.rb @@ -12,7 +12,10 @@ module Configuration # TODO: mark as `@public_api` when GA class Settings < Datadog::Tracing::Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end o.lazy end @@ -22,7 +25,8 @@ class Settings < Datadog::Tracing::Contrib::Configuration::Settings end option :operation_name do |o| - o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME } + o.env_var Ext::ENV_OPERATION_NAME + o.default ENV[Ext::OPERATION_NAME] o.lazy end end diff --git a/lib/datadog/core/configuration/option.rb b/lib/datadog/core/configuration/option.rb index a129b95209e..7decda20fb1 100644 --- a/lib/datadog/core/configuration/option.rb +++ b/lib/datadog/core/configuration/option.rb @@ -62,7 +62,7 @@ def get elsif definition.delegate_to context_eval(&definition.delegate_to) else - set(default_value, precedence: Precedence::DEFAULT) + set_value_from_env_or_default end end @@ -102,6 +102,19 @@ def context_eval(&block) @context.instance_eval(&block) end + def set_value_from_env_or_default + if definition.env_var && ENV[definition.env_var] + set(ENV[definition.env_var], precedence: Precedence::PROGRAMMATIC) + elsif definition.deprecated_env_var && ENV[definition.deprecated_env_var] + Datadog::Core.log_deprecation do + "#{definition.deprecated_env_var} environment variable is deprecated, use #{definition.env_var} instead." + end + set(ENV[definition.deprecated_env_var], precedence: Precedence::PROGRAMMATIC) + else + set(default_value, precedence: Precedence::DEFAULT) + end + end + # Used for testing attr_reader :precedence_set private :precedence_set diff --git a/lib/datadog/core/configuration/option_definition.rb b/lib/datadog/core/configuration/option_definition.rb index 5df8c94451f..80b6dfbc3e7 100644 --- a/lib/datadog/core/configuration/option_definition.rb +++ b/lib/datadog/core/configuration/option_definition.rb @@ -11,6 +11,8 @@ class OptionDefinition attr_reader \ :default, + :env_var, + :deprecated_env_var, :delegate_to, :depends_on, :lazy, @@ -22,6 +24,8 @@ class OptionDefinition def initialize(name, meta = {}, &block) @default = meta[:default] + @env_var = meta[:env_var] + @deprecated_env_var = meta[:deprecated_env_var] @delegate_to = meta[:delegate_to] @depends_on = meta[:depends_on] || [] @lazy = meta[:lazy] || false @@ -44,6 +48,8 @@ class Builder :helpers def initialize(name, options = {}) + @env_var = nil + @deprecated_env_var = nil @default = nil @delegate_to = nil @depends_on = [] @@ -66,6 +72,14 @@ def depends_on(*values) @depends_on = values.flatten end + def env_var(value) + @env_var = value + end + + def deprecated_env_var(value) + @deprecated_env_var = value + end + def default(value = nil, &block) @default = block || value end @@ -103,6 +117,8 @@ def apply_options!(options = {}) return if options.nil? || options.empty? default(options[:default]) if options.key?(:default) + env_var(options[:env_var]) if options.key?(:env_var) + deprecated_env_var(options[:deprecated_env_var]) if options.key?(:deprecated_env_var) delegate_to(&options[:delegate_to]) if options.key?(:delegate_to) depends_on(*options[:depends_on]) if options.key?(:depends_on) lazy(options[:lazy]) if options.key?(:lazy) @@ -119,6 +135,8 @@ def to_definition def meta { default: @default, + env_var: @env_var, + deprecated_env_var: @deprecated_env_var, delegate_to: @delegate_to, depends_on: @depends_on, lazy: @lazy, diff --git a/lib/datadog/core/configuration/settings.rb b/lib/datadog/core/configuration/settings.rb index 8714cecae71..598ccc75d35 100644 --- a/lib/datadog/core/configuration/settings.rb +++ b/lib/datadog/core/configuration/settings.rb @@ -79,7 +79,8 @@ def initialize(*_) # @default `DD_API_KEY` environment variable, otherwise `nil` # @return [String,nil] option :api_key do |o| - o.default { ENV.fetch(Core::Environment::Ext::ENV_API_KEY, nil) } + o.env_var Core::Environment::Ext::ENV_API_KEY + o.default { nil } o.lazy end @@ -99,8 +100,11 @@ def initialize(*_) # @default `DD_TRACE_DEBUG` environment variable, otherwise `false` # @return [Boolean] option :debug do |o| - o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED, false) } - o.lazy + o.env_var Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end o.on_set do |enabled| # Enable rich debug print statements. # We do not need to unnecessarily load 'pp' unless in debugging mode. @@ -117,8 +121,11 @@ def initialize(*_) # @default `DD_HEALTH_METRICS_ENABLED` environment variable, otherwise `false` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED, false) } - o.lazy + o.env_var Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end end # {Datadog::Statsd} instance to collect health metrics. @@ -143,8 +150,11 @@ def initialize(*_) # @return [Boolean,nil] option :enabled do |o| # Defaults to nil as we want to know when the default value is being used - o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_STARTUP_LOGS_ENABLED, nil) } - o.lazy + o.env_var Datadog::Core::Configuration::Ext::Diagnostics::ENV_STARTUP_LOGS_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end end end end @@ -158,8 +168,8 @@ def initialize(*_) 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.default { ENV.fetch(Core::Environment::Ext::ENV_ENVIRONMENT, nil) } - o.lazy + o.env_var Core::Environment::Ext::ENV_ENVIRONMENT + o.default nil end # Internal `Datadog.logger` configuration. @@ -194,8 +204,11 @@ def initialize(*_) # @default `DD_PROFILING_ENABLED` environment variable, otherwise `false` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Profiling::Ext::ENV_ENABLED, false) } - o.lazy + o.env_var Profiling::Ext::ENV_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end end # @public_api @@ -228,8 +241,10 @@ def initialize(*_) # # @default `DD_PROFILING_MAX_FRAMES` environment variable, otherwise 400 option :max_frames do |o| - o.default { env_to_int(Profiling::Ext::ENV_MAX_FRAMES, 400) } - o.lazy + o.env_var Profiling::Ext::ENV_MAX_FRAMES + o.setter do |value| + val_to_int(value, 400) + end end # @public_api @@ -241,8 +256,11 @@ def initialize(*_) # @default `DD_PROFILING_ENDPOINT_COLLECTION_ENABLED` environment variable, otherwise `true` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Profiling::Ext::ENV_ENDPOINT_COLLECTION_ENABLED, true) } - o.lazy + o.env_var Profiling::Ext::ENV_ENDPOINT_COLLECTION_ENABLED + o.default true + o.setter do |value| + val_to_bool(value) + end end end end @@ -284,8 +302,11 @@ def initialize(*_) # # @default `DD_PROFILING_FORCE_ENABLE_LEGACY` environment variable, otherwise `false` option :force_enable_legacy_profiler do |o| - o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_LEGACY', false) } - o.lazy + o.env_var 'DD_PROFILING_FORCE_ENABLE_LEGACY' + o.default false + o.setter do |value| + val_to_bool(value) + end o.on_set do |value| if value Datadog.logger.warn( @@ -317,8 +338,10 @@ def initialize(*_) # # @default `DD_PROFILING_FORCE_ENABLE_GC` environment variable, otherwise `false` option :force_enable_gc_profiling do |o| - o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_GC', false) } - o.lazy + o.env_var 'DD_PROFILING_FORCE_ENABLE_GC' + o.setter do |value| + val_to_bool(value) + end end # Can be used to enable/disable the Datadog::Profiling.allocation_count feature. @@ -339,8 +362,11 @@ def initialize(*_) # # @default `DD_PROFILING_SKIP_MYSQL2_CHECK` environment variable, otherwise `false` option :skip_mysql2_check do |o| - o.default { env_to_bool('DD_PROFILING_SKIP_MYSQL2_CHECK', false) } - o.lazy + o.env_var 'DD_PROFILING_SKIP_MYSQL2_CHECK' + o.default false + o.setter do |value| + val_to_bool(value) + end end # The profiler gathers data by sending `SIGPROF` unix signals to Ruby application threads. @@ -363,8 +389,15 @@ def initialize(*_) # # @default `DD_PROFILING_NO_SIGNALS_WORKAROUND_ENABLED` environment variable as a boolean, otherwise `:auto` option :no_signals_workaround_enabled do |o| - o.default { env_to_bool('DD_PROFILING_NO_SIGNALS_WORKAROUND_ENABLED', :auto) } - o.lazy + o.env_var 'DD_PROFILING_NO_SIGNALS_WORKAROUND_ENABLED' + o.default :auto + o.setter do |value| + if value != :auto + val_to_bool(value) + else + value + end + end end end @@ -374,9 +407,11 @@ def initialize(*_) # # @default `DD_PROFILING_UPLOAD_TIMEOUT` environment variable, otherwise `30.0` option :timeout_seconds do |o| - o.setter { |value| value.nil? ? 30.0 : value.to_f } - o.default { env_to_float(Profiling::Ext::ENV_UPLOAD_TIMEOUT, 30.0) } - o.lazy + o.env_var Profiling::Ext::ENV_UPLOAD_TIMEOUT + o.default 30.0 + o.setter do |value| + val_to_float(value, 30.0) + end end end end @@ -389,8 +424,11 @@ def initialize(*_) # @default `DD_RUNTIME_METRICS_ENABLED` environment variable, otherwise `false` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Core::Runtime::Ext::Metrics::ENV_ENABLED, false) } - o.lazy + o.env_var Core::Runtime::Ext::Metrics::ENV_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end end option :opts, default: ->(_i) { {} }, lazy: true @@ -406,7 +444,8 @@ def initialize(*_) 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.default { ENV.fetch(Core::Environment::Ext::ENV_SERVICE, Core::Environment::Ext::FALLBACK_SERVICE_NAME) } + o.env_var Core::Environment::Ext::ENV_SERVICE + o.default { 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 @@ -429,7 +468,8 @@ def initialize(*_) # @default `DD_SITE` environment variable, otherwise `nil` which sends data to `app.datadoghq.com` # @return [String,nil] option :site do |o| - o.default { ENV.fetch(Core::Environment::Ext::ENV_SITE, nil) } + o.env_var Core::Environment::Ext::ENV_SITE + o.default { nil } o.lazy end @@ -440,43 +480,45 @@ def initialize(*_) # @default `DD_TAGS` environment variable (in the format `'tag1:value1,tag2:value2'`), otherwise `{}` # @return [Hash] option :tags do |o| - o.default do - tags = {} - - # Parse tags from environment - env_to_list(Core::Environment::Ext::ENV_TAGS, comma_separated_only: false).each do |tag| - key, value = tag.split(':', 2) - tags[key] = value if value && !value.empty? - end + o.env_var Core::Environment::Ext::ENV_TAGS + o.default { {} } + o.setter do |new_value, old_value| + tag_list = if new_value && new_value.is_a?(String) + val_to_list(new_value, comma_separated_only: false).each_with_object({}) do |tag, tags| + key, value = tag.split(':', 2) + tags[key] = value if value && !value.empty? + end + else + new_value + end + + env_value = env + version_value = version + service_name = service_without_fallback # Override tags if defined - tags[Core::Environment::Ext::TAG_ENV] = env unless env.nil? - tags[Core::Environment::Ext::TAG_VERSION] = version unless version.nil? - - tags - end + tag_list[Core::Environment::Ext::TAG_ENV] = env_value unless env_value.nil? + tag_list[Core::Environment::Ext::TAG_VERSION] = version_value unless version_value.nil? - o.setter do |new_value, old_value| # Coerce keys to strings - string_tags = new_value.collect { |k, v| [k.to_s, v] }.to_h + string_tags = tag_list.collect { |k, v| [k.to_s, v] }.to_h # Cross-populate tag values with other settings if env.nil? && string_tags.key?(Core::Environment::Ext::TAG_ENV) self.env = string_tags[Core::Environment::Ext::TAG_ENV] end - if version.nil? && string_tags.key?(Core::Environment::Ext::TAG_VERSION) + if version_value.nil? && string_tags.key?(Core::Environment::Ext::TAG_VERSION) self.version = string_tags[Core::Environment::Ext::TAG_VERSION] end - if service_without_fallback.nil? && string_tags.key?(Core::Environment::Ext::TAG_SERVICE) + 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 - o.lazy end @@ -511,7 +553,8 @@ def initialize(*_) # @return [String,nil] 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.env_var Core::Environment::Ext::ENV_VERSION + o.default { nil } o.lazy end @@ -524,8 +567,11 @@ def initialize(*_) # Can be disabled as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection). # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Core::Telemetry::Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Core::Telemetry::Ext::ENV_ENABLED + o.default true + o.setter do |value| + val_to_bool(value) + end end # The interval in seconds when telemetry must be sent. @@ -536,8 +582,11 @@ def initialize(*_) # @return [Float] # @!visibility private option :heartbeat_interval_seconds do |o| - o.default { env_to_float(Core::Telemetry::Ext::ENV_HEARTBEAT_INTERVAL, 60) } - o.lazy + o.env_var Core::Telemetry::Ext::ENV_HEARTBEAT_INTERVAL + o.default 60 + o.setter do |value| + val_to_float(value, 60) + end end end @@ -549,8 +598,11 @@ def initialize(*_) # @default `DD_REMOTE_CONFIGURATION_ENABLED` environment variable, otherwise `true`. # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Core::Remote::Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Core::Remote::Ext::ENV_ENABLED + o.default true + o.setter do |value| + val_to_bool(value) + end end # Tune remote configuration polling interval. @@ -558,8 +610,11 @@ def initialize(*_) # @default `DD_REMOTE_CONFIGURATION_POLL_INTERVAL_SECONDS` environment variable, otherwise `5.0` seconds. # @return [Float] option :poll_interval_seconds do |o| - o.default { env_to_float(Core::Remote::Ext::ENV_POLL_INTERVAL_SECONDS, 5.0) } - o.lazy + o.env_var Core::Remote::Ext::ENV_POLL_INTERVAL_SECONDS + o.default 5.0 + o.setter do |value| + val_to_float(value, 5.0) + end end # Declare service name to bind to remote configuration. Use when diff --git a/lib/datadog/core/environment/variable_helpers.rb b/lib/datadog/core/environment/variable_helpers.rb index ac56e7b3dc3..8bef863d8eb 100644 --- a/lib/datadog/core/environment/variable_helpers.rb +++ b/lib/datadog/core/environment/variable_helpers.rb @@ -9,52 +9,34 @@ module Environment module VariableHelpers extend self - # Reads an environment variable as a Boolean. + # Reads an variable as a Boolean. # - # @param [String] var environment variable - # @param [Array] var list of environment variables - # @param [Boolean] default the default value if the keys in `var` are not present in the environment - # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when - # the first key in `var` is not used. - # @return [Boolean] if the environment value is the string `true` or `1` - # @return [default] if the environment value is not found - def env_to_bool(var, default = nil, deprecation_warning: true) - var = decode_array(var, deprecation_warning) - if var && ENV.key?(var) - value = ENV[var].to_s.strip - value.downcase! - value == 'true' || value == '1' # rubocop:disable Style/MultipleComparison - else - default - end + # @param [String] val + # @return [Boolean] if the value is the string `true` or `1` + def val_to_bool(val) + value = val.to_s.strip + value.downcase! + value == 'true' || value == '1' # rubocop:disable Style/MultipleComparison end - # Reads an environment variable as an Integer. + # Reads an variable as an Integer. # - # @param [String] var environment variable - # @param [Array] var list of environment variables + # @param [String] val # @param [Integer] default the default value if the keys in `var` are not present in the environment - # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when - # the first key in `var` is not used. # @return [Integer] if the environment value is a valid Integer # @return [default] if the environment value is not found - def env_to_int(var, default = nil, deprecation_warning: true) - var = decode_array(var, deprecation_warning) - var && ENV.key?(var) ? ENV[var].to_i : default + def val_to_int(val, default = nil) + val ? val.to_i : default end - # Reads an environment variable as a Float. + # Reads an variable as a Float. # - # @param [String] var environment variable - # @param [Array] var list of environment variables + # @param [String] val # @param [Float] default the default value if the keys in `var` are not present in the environment - # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when - # the first key in `var` is not used. # @return [Float] if the environment value is a valid Float # @return [default] if the environment value is not found - def env_to_float(var, default = nil, deprecation_warning: true) - var = decode_array(var, deprecation_warning) - var && ENV.key?(var) ? ENV[var].to_f : default + def val_to_float(val, default = nil) + val ? val.to_f : default end # Parses comma- or space-separated lists. @@ -67,22 +49,18 @@ def env_to_float(var, default = nil, deprecation_warning: true) # # Empty entries, after trimmed, are also removed from the result. # - # @param [String] var environment variable - # @param [Array] var list of environment variables + # @param [String] val environment variable # @param [Array] default the default value if the keys in `var` are not present in the environment - # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when - # the first key in `var` is not used. # @return [Array] if the environment value is a valid list # @return [default] if the environment value is not found - def env_to_list(var, default = [], comma_separated_only:, deprecation_warning: true) - var = decode_array(var, deprecation_warning) - if var && ENV.key?(var) - value = ENV[var] - - values = if value.include?(',') || comma_separated_only - value.split(',') + def val_to_list(val, default = [], comma_separated_only:) + if val + values = if val.is_a?(Array) + val + elsif val.include?(',') || comma_separated_only + val.split(',') else - value.split(' ') # rubocop:disable Style/RedundantArgument + val.split(' ') # rubocop:disable Style/RedundantArgument end values.map! do |v| @@ -97,25 +75,6 @@ def env_to_list(var, default = [], comma_separated_only:, deprecation_warning: t default end end - - private - - def decode_array(var, deprecation_warning) - if var.is_a?(Array) - var.find.with_index do |env_var, i| - found = ENV.key?(env_var) - - # Check if we are using a non-preferred environment variable - if deprecation_warning && found && i != 0 - Datadog::Core.log_deprecation { "#{env_var} environment variable is deprecated, use #{var.first} instead." } - end - - found - end - else - var - end - end end end end diff --git a/lib/datadog/profiling/http_transport.rb b/lib/datadog/profiling/http_transport.rb index d9c6265ad7c..b915aec5290 100644 --- a/lib/datadog/profiling/http_transport.rb +++ b/lib/datadog/profiling/http_transport.rb @@ -91,7 +91,7 @@ def validate_agent_settings(agent_settings) end def agentless?(site, api_key) - site && api_key && Core::Environment::VariableHelpers.env_to_bool(Profiling::Ext::ENV_AGENTLESS, false) + site && api_key && Core::Environment::VariableHelpers.val_to_bool(Profiling::Ext::ENV_AGENTLESS) end def validate_exporter(exporter_configuration) diff --git a/lib/datadog/tracing/configuration/settings.rb b/lib/datadog/tracing/configuration/settings.rb index 95bf32d6c78..d4c9dc954da 100644 --- a/lib/datadog/tracing/configuration/settings.rb +++ b/lib/datadog/tracing/configuration/settings.rb @@ -26,8 +26,10 @@ def self.extended(base) # @default `DD_TRACE_ANALYTICS_ENABLED` environment variable, otherwise `nil` # @return [Boolean,nil] option :enabled do |o| - o.default { env_to_bool(Tracing::Configuration::Ext::Analytics::ENV_TRACE_ANALYTICS_ENABLED, nil) } - o.lazy + o.env_var Tracing::Configuration::Ext::Analytics::ENV_TRACE_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end end @@ -51,14 +53,13 @@ def self.extended(base) # otherwise `['Datadog','b3multi','b3']`. # @return [Array] option :propagation_extract_style do |o| - o.default do + o.deprecated_env_var Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_EXTRACT_OLD + o.env_var Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_EXTRACT + o.setter do |value| # DEV-2.0: Change default value to `tracecontext, Datadog`. # Look for all headers by default - env_to_list( - [ - Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_EXTRACT, - Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_EXTRACT_OLD - ], + val_to_list( + value, [ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG, Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER, @@ -82,8 +83,6 @@ def self.extended(base) end end end - - o.lazy end # The data propagation styles the tracer will use to inject distributed tracing propagation @@ -94,13 +93,12 @@ def self.extended(base) # @default `DD_TRACE_PROPAGATION_STYLE_INJECT` environment variable (comma-separated list), otherwise `['Datadog']`. # @return [Array] option :propagation_inject_style do |o| - o.default do + o.deprecated_env_var Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT_OLD + o.env_var Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT + o.setter do |value| # DEV-2.0: Change default value to `tracecontext, Datadog`. - env_to_list( - [ - Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT, - Tracing::Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE_INJECT_OLD - ], + val_to_list( + value, [Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG], comma_separated_only: true # Only inject Datadog headers by default ) @@ -120,8 +118,6 @@ def self.extended(base) end end end - - o.lazy end # An ordered list of what data propagation styles the tracer will use to extract distributed tracing propagation @@ -133,8 +129,9 @@ def self.extended(base) # @default `DD_TRACE_PROPAGATION_STYLE` environment variable (comma-separated list). # @return [Array] option :propagation_style do |o| - o.default do - env_to_list(Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE, nil, comma_separated_only: true) + o.env_var Configuration::Ext::Distributed::ENV_PROPAGATION_STYLE + o.setter do |value| + val_to_list(value, nil, comma_separated_only: true) end o.on_set do |styles| @@ -156,8 +153,6 @@ def self.extended(base) set_option(:propagation_extract_style, styles) set_option(:propagation_inject_style, styles) end - - o.lazy end end @@ -169,8 +164,8 @@ def self.extended(base) # @default `DD_TRACE_ENABLED` environment variable, otherwise `true` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Tracing::Configuration::Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Tracing::Configuration::Ext::ENV_ENABLED + o.default true end # Enable 128 bit trace id generation. @@ -178,8 +173,11 @@ def self.extended(base) # @default `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` environment variable, otherwise `false` # @return [Boolean] option :trace_id_128_bit_generation_enabled do |o| - o.default { env_to_bool(Tracing::Configuration::Ext::ENV_TRACE_ID_128_BIT_GENERATION_ENABLED, false) } - o.lazy + o.env_var Tracing::Configuration::Ext::ENV_TRACE_ID_128_BIT_GENERATION_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end end # Enable 128 bit trace id injected for logging. @@ -189,8 +187,11 @@ def self.extended(base) # # It is not supported by our backend yet. Do not enable it. option :trace_id_128_bit_logging_enabled do |o| - o.default { env_to_bool(Tracing::Configuration::Ext::Correlation::ENV_TRACE_ID_128_BIT_LOGGING_ENABLED, false) } - o.lazy + o.env_var Tracing::Configuration::Ext::Correlation::ENV_TRACE_ID_128_BIT_LOGGING_ENABLED + o.default false + o.setter do |value| + val_to_bool(value) + end end # A custom tracer instance. @@ -211,8 +212,11 @@ def self.extended(base) # @see https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#trace-correlation # @return [Boolean] option :log_injection do |o| - o.default { env_to_bool(Tracing::Configuration::Ext::Correlation::ENV_LOGS_INJECTION_ENABLED, true) } - o.lazy + o.env_var Tracing::Configuration::Ext::Correlation::ENV_LOGS_INJECTION_ENABLED + o.default true + o.setter do |value| + val_to_bool(value) + end end # Configures an alternative trace transport behavior, where @@ -252,8 +256,11 @@ def self.extended(base) option :priority_sampling option :report_hostname do |o| - o.default { env_to_bool(Tracing::Configuration::Ext::NET::ENV_REPORT_HOSTNAME, false) } - o.lazy + o.env_var Tracing::Configuration::Ext::NET::ENV_REPORT_HOSTNAME + o.default false + o.setter do |value| + val_to_bool(value) + end end # A custom sampler instance. @@ -275,8 +282,10 @@ def self.extended(base) # @default `DD_TRACE_SAMPLE_RATE` environment variable, otherwise `nil`. # @return [Float,nil] option :default_rate do |o| - o.default { env_to_float(Tracing::Configuration::Ext::Sampling::ENV_SAMPLE_RATE, nil) } - o.lazy + o.env_var Tracing::Configuration::Ext::Sampling::ENV_SAMPLE_RATE + o.setter do |value| + val_to_float(value, nil) + end end # Rate limit for number of spans per second. @@ -287,8 +296,10 @@ def self.extended(base) # @default `DD_TRACE_RATE_LIMIT` environment variable, otherwise 100. # @return [Numeric,nil] option :rate_limit do |o| - o.default { env_to_float(Tracing::Configuration::Ext::Sampling::ENV_RATE_LIMIT, 100) } - o.lazy + o.env_var Tracing::Configuration::Ext::Sampling::ENV_RATE_LIMIT + o.setter do |value| + val_to_float(value, 100) + end end # Single span sampling rules. @@ -344,8 +355,10 @@ def self.extended(base) # @default `DD_TRACE_TEST_MODE_ENABLED` environment variable, otherwise `false` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Tracing::Configuration::Ext::Test::ENV_MODE_ENABLED, false) } - o.lazy + o.env_var Tracing::Configuration::Ext::Test::ENV_MODE_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :trace_flush do |o| @@ -399,18 +412,20 @@ def self.extended(base) # @return [Boolean] option :enabled do |o| o.default do - disabled = env_to_bool(Tracing::Configuration::Ext::ClientIp::ENV_DISABLED) + disabled = ENV[Tracing::Configuration::Ext::ClientIp::ENV_DISABLED] enabled = if disabled.nil? false else - Datadog.logger.warn { "#{Tracing::Configuration::Ext::ClientIp::ENV_DISABLED} environment variable is deprecated, found set to #{disabled}, use #{Tracing::Configuration::Ext::ClientIp::ENV_ENABLED}=#{!disabled}" } + Datadog::Core.log_deprecation do + "#{Tracing::Configuration::Ext::ClientIp::ENV_DISABLED} environment variable is deprecated, use #{Tracing::Configuration::Ext::ClientIp::ENV_ENABLED} instead." + end !disabled end # ENABLED env var takes precedence over deprecated DISABLED - env_to_bool(Tracing::Configuration::Ext::ClientIp::ENV_ENABLED, enabled) + val_to_bool(ENV[Tracing::Configuration::Ext::ClientIp::ENV_ENABLED]) end o.lazy end @@ -420,7 +435,8 @@ def self.extended(base) # @default `DD_TRACE_CLIENT_IP_HEADER` environment variable, otherwise `nil`. # @return [String,nil] option :header_name do |o| - o.default { ENV.fetch(Tracing::Configuration::Ext::ClientIp::ENV_HEADER_NAME, nil) } + o.env_var Tracing::Configuration::Ext::ClientIp::ENV_HEADER_NAME + o.default { nil } o.lazy end end @@ -434,8 +450,10 @@ def self.extended(base) # @default `DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH` environment variable, otherwise `512` # @return [Integer] option :x_datadog_tags_max_length do |o| - o.default { env_to_int(Tracing::Configuration::Ext::Distributed::ENV_X_DATADOG_TAGS_MAX_LENGTH, 512) } - o.lazy + o.env_var Tracing::Configuration::Ext::Distributed::ENV_X_DATADOG_TAGS_MAX_LENGTH + o.setter do |value| + val_to_int(value, 512) + end end # Schema version for span attributes that enables various features @@ -443,13 +461,8 @@ def self.extended(base) # @default `DD_TRACE_SPAN_ATTRIBUTE_SCHEMA` environment variable, otherwise default `v0` currently # @return [String] option :span_attribute_schema do |o| - o.default do - ENV.fetch( - Tracing::Configuration::Ext::SpanAttributeSchema::ENV_SPAN_ATTRIBUTE_SCHEMA, - Tracing::Configuration::Ext::SpanAttributeSchema::DEFAULT_VERSION - ) - end - o.lazy + o.env_var Tracing::Configuration::Ext::SpanAttributeSchema::ENV_SPAN_ATTRIBUTE_SCHEMA + o.default Tracing::Configuration::Ext::SpanAttributeSchema::DEFAULT_VERSION end end end diff --git a/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb b/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb index 8eb85f08480..b3ff73cd5fe 100644 --- a/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb b/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb index d54272cb59b..2ee74e96480 100644 --- a/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb b/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb index 1bbe0b9cfa2..bf5d2dad316 100644 --- a/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end # DEV-2.0: Breaking changes for removal. diff --git a/lib/datadog/tracing/contrib/action_view/configuration/settings.rb b/lib/datadog/tracing/contrib/action_view/configuration/settings.rb index c01cc53521a..bd9c81cb5bc 100644 --- a/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/action_view/configuration/settings.rb @@ -10,18 +10,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/active_job/configuration/settings.rb b/lib/datadog/tracing/contrib/active_job/configuration/settings.rb index 8c0a4e54dde..9f55407051e 100644 --- a/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/active_job/configuration/settings.rb @@ -13,18 +13,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb b/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb index f2e7faec952..40062029674 100644 --- a/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end end end diff --git a/lib/datadog/tracing/contrib/active_record/configuration/settings.rb b/lib/datadog/tracing/contrib/active_record/configuration/settings.rb index 814c9dc942f..3d7656ef1c1 100644 --- a/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/active_record/configuration/settings.rb @@ -13,18 +13,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name do |o| @@ -34,7 +40,6 @@ class Settings < Contrib::Configuration::Settings Utils.adapter_name ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/active_support/configuration/settings.rb b/lib/datadog/tracing/contrib/active_support/configuration/settings.rb index efbf2901ef9..fc6900eb8c4 100644 --- a/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/active_support/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :cache_service do |o| @@ -33,7 +39,6 @@ class Settings < Contrib::Configuration::Settings Ext::SERVICE_CACHE ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/aws/configuration/settings.rb b/lib/datadog/tracing/contrib/aws/configuration/settings.rb index dae91cc01f7..e837fe60872 100644 --- a/lib/datadog/tracing/contrib/aws/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/aws/configuration/settings.rb @@ -13,28 +13,34 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb b/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb index 33b26ce41d3..afecc2dbc8f 100644 --- a/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb @@ -12,8 +12,10 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end end end diff --git a/lib/datadog/tracing/contrib/dalli/configuration/settings.rb b/lib/datadog/tracing/contrib/dalli/configuration/settings.rb index bd7be22c907..29e0413b926 100644 --- a/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/dalli/configuration/settings.rb @@ -12,28 +12,34 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb b/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb index c97f4b63da8..bda6141f399 100644 --- a/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb @@ -13,18 +13,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb b/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb index cfb0d142916..fba2a570514 100644 --- a/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb @@ -12,30 +12,36 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :quantize, default: {} option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/ethon/configuration/settings.rb b/lib/datadog/tracing/contrib/ethon/configuration/settings.rb index 13b3115ab9b..0b60c85a880 100644 --- a/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/ethon/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true @@ -31,13 +37,13 @@ class Settings < Contrib::Configuration::Settings option :split_by_domain, default: false option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/excon/configuration/settings.rb b/lib/datadog/tracing/contrib/excon/configuration/settings.rb index 7a582fcd41a..f97a1c3cc12 100644 --- a/lib/datadog/tracing/contrib/excon/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/excon/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true @@ -31,13 +37,13 @@ class Settings < Contrib::Configuration::Settings option :split_by_domain, default: false option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/faraday/configuration/settings.rb b/lib/datadog/tracing/contrib/faraday/configuration/settings.rb index 15bf69f650f..31036b51557 100644 --- a/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/faraday/configuration/settings.rb @@ -16,18 +16,24 @@ class Settings < Contrib::Configuration::Settings end option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true @@ -35,13 +41,13 @@ class Settings < Contrib::Configuration::Settings option :split_by_domain, default: false option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/grape/configuration/settings.rb b/lib/datadog/tracing/contrib/grape/configuration/settings.rb index 0c95b6189e2..74554500b1f 100644 --- a/lib/datadog/tracing/contrib/grape/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/grape/configuration/settings.rb @@ -13,18 +13,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/graphql/configuration/settings.rb b/lib/datadog/tracing/contrib/graphql/configuration/settings.rb index 6e78982aaa6..2fd13e8fb9a 100644 --- a/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/graphql/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :schemas diff --git a/lib/datadog/tracing/contrib/grpc/configuration/settings.rb b/lib/datadog/tracing/contrib/grpc/configuration/settings.rb index 482273004b4..f2ab43063fc 100644 --- a/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/grpc/configuration/settings.rb @@ -13,30 +13,36 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end option :error_handler, default: Tracing::SpanOperation::Events::DEFAULT_ON_ERROR diff --git a/lib/datadog/tracing/contrib/hanami/configuration/settings.rb b/lib/datadog/tracing/contrib/hanami/configuration/settings.rb index 99abe0a567b..4a7733c6b37 100644 --- a/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/hanami/configuration/settings.rb @@ -11,8 +11,10 @@ module Configuration # Configuration for Hanami instrumentation class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end end end diff --git a/lib/datadog/tracing/contrib/http/configuration/settings.rb b/lib/datadog/tracing/contrib/http/configuration/settings.rb index 3f870ecbad1..3587a5020b5 100644 --- a/lib/datadog/tracing/contrib/http/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/http/configuration/settings.rb @@ -12,35 +12,43 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end option :error_status_codes do |o| - o.default { env_to_list(Ext::ENV_ERROR_STATUS_CODES, 400...600, comma_separated_only: false) } - o.lazy + o.env_var Ext::ENV_ERROR_STATUS_CODES + o.setter do |value| + val_to_list(value, 400...600, comma_separated_only: false) + end end option :split_by_domain, default: false diff --git a/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb b/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb index 67789c5f060..17a93ab6251 100644 --- a/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb @@ -12,35 +12,43 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end option :error_status_codes do |o| - o.default { env_to_list(Ext::ENV_ERROR_STATUS_CODES, 400...600, comma_separated_only: false) } - o.lazy + o.env_var Ext::ENV_ERROR_STATUS_CODES + o.setter do |value| + val_to_list(value, 400...600, comma_separated_only: false) + end end option :split_by_domain, default: false diff --git a/lib/datadog/tracing/contrib/httprb/configuration/settings.rb b/lib/datadog/tracing/contrib/httprb/configuration/settings.rb index 9534c5236fd..d794d1f8bc7 100644 --- a/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/httprb/configuration/settings.rb @@ -12,35 +12,43 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end option :error_status_codes do |o| - o.default { env_to_list(Ext::ENV_ERROR_STATUS_CODES, 400...600, comma_separated_only: false) } - o.lazy + o.env_var Ext::ENV_ERROR_STATUS_CODES + o.setter do |value| + value_to_list(value, 400...600, comma_separated_only: false) + end end option :split_by_domain, default: false diff --git a/lib/datadog/tracing/contrib/kafka/configuration/settings.rb b/lib/datadog/tracing/contrib/kafka/configuration/settings.rb index 12b561ee8d5..6e3eb8b87fb 100644 --- a/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/kafka/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/lograge/configuration/settings.rb b/lib/datadog/tracing/contrib/lograge/configuration/settings.rb index facbc4d9864..efa172170e3 100644 --- a/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/lograge/configuration/settings.rb @@ -12,8 +12,10 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end end end diff --git a/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb b/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb index 3b001f0f253..8f513a5a5ce 100644 --- a/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb @@ -14,30 +14,36 @@ class Settings < Contrib::Configuration::Settings DEFAULT_QUANTIZE = { show: [:collection, :database, :operation] }.freeze option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :quantize, default: DEFAULT_QUANTIZE option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb b/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb index fdd53d8c03d..8a1cd1ed131 100644 --- a/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb @@ -14,38 +14,39 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end option :comment_propagation do |o| - o.default do - ENV.fetch( - Contrib::Propagation::SqlComment::Ext::ENV_DBM_PROPAGATION_MODE, - Contrib::Propagation::SqlComment::Ext::DISABLED - ) - end - o.lazy + o.env_var Contrib::Propagation::SqlComment::Ext::ENV_DBM_PROPAGATION_MODE + o.default Contrib::Propagation::SqlComment::Ext::DISABLED end end end diff --git a/lib/datadog/tracing/contrib/pg/configuration/settings.rb b/lib/datadog/tracing/contrib/pg/configuration/settings.rb index 31e7560b9c2..bcb6e759135 100644 --- a/lib/datadog/tracing/contrib/pg/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/pg/configuration/settings.rb @@ -14,38 +14,39 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end option :comment_propagation do |o| - o.default do - ENV.fetch( - Contrib::Propagation::SqlComment::Ext::ENV_DBM_PROPAGATION_MODE, - Contrib::Propagation::SqlComment::Ext::DISABLED - ) - end - o.lazy + o.env_var Contrib::Propagation::SqlComment::Ext::ENV_DBM_PROPAGATION_MODE + o.default Contrib::Propagation::SqlComment::Ext::DISABLED end end end diff --git a/lib/datadog/tracing/contrib/presto/configuration/settings.rb b/lib/datadog/tracing/contrib/presto/configuration/settings.rb index 65465ed19d9..acb3a566ae2 100644 --- a/lib/datadog/tracing/contrib/presto/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/presto/configuration/settings.rb @@ -12,28 +12,34 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/qless/configuration/settings.rb b/lib/datadog/tracing/contrib/qless/configuration/settings.rb index a0c67f78ffd..381071f6c94 100644 --- a/lib/datadog/tracing/contrib/qless/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/qless/configuration/settings.rb @@ -12,23 +12,31 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :tag_job_data do |o| - o.default { env_to_bool(Ext::ENV_TAG_JOB_DATA, false) } - o.lazy + o.env_var Ext::ENV_TAG_JOB_DATA + o.setter do |value| + val_to_bool(value) + end end option :tag_job_tags do |o| - o.default { env_to_bool(Ext::ENV_TAG_JOB_TAGS, false) } - o.lazy + o.env_var Ext::ENV_TAG_JOB_TAGS + o.setter do |value| + val_to_bool(value) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/que/configuration/settings.rb b/lib/datadog/tracing/contrib/que/configuration/settings.rb index 9682d69ebac..edb944ab1bd 100644 --- a/lib/datadog/tracing/contrib/que/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/que/configuration/settings.rb @@ -15,28 +15,38 @@ class Settings < Contrib::Configuration::Settings option :distributed_tracing, default: true option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :tag_args do |o| - o.default { env_to_bool(Ext::ENV_TAG_ARGS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_TAG_ARGS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :tag_data do |o| - o.default { env_to_bool(Ext::ENV_TAG_DATA_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_TAG_DATA_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :error_handler, default: Tracing::SpanOperation::Events::DEFAULT_ON_ERROR end diff --git a/lib/datadog/tracing/contrib/racecar/configuration/settings.rb b/lib/datadog/tracing/contrib/racecar/configuration/settings.rb index 899383f0339..8e14171b982 100644 --- a/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/racecar/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name do |o| @@ -33,7 +39,6 @@ class Settings < Contrib::Configuration::Settings Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/rack/configuration/settings.rb b/lib/datadog/tracing/contrib/rack/configuration/settings.rb index 277bd8d0cc6..217ee15c53a 100644 --- a/lib/datadog/tracing/contrib/rack/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/rack/configuration/settings.rb @@ -17,18 +17,24 @@ class Settings < Contrib::Configuration::Settings }.freeze option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :application diff --git a/lib/datadog/tracing/contrib/rails/configuration/settings.rb b/lib/datadog/tracing/contrib/rails/configuration/settings.rb index 0c73604349a..3238e3da2ea 100644 --- a/lib/datadog/tracing/contrib/rails/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/rails/configuration/settings.rb @@ -24,13 +24,18 @@ def initialize(options = {}) end option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end + o.on_set do |value| # Update ActionPack analytics too Datadog.configuration.tracing[:action_pack][:analytics_enabled] = value @@ -38,8 +43,11 @@ def initialize(options = {}) end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end + o.on_set do |value| # Update ActionPack analytics too Datadog.configuration.tracing[:action_pack][:analytics_sample_rate] = value diff --git a/lib/datadog/tracing/contrib/rake/configuration/settings.rb b/lib/datadog/tracing/contrib/rake/configuration/settings.rb index d49d02e463c..17f07b06e44 100644 --- a/lib/datadog/tracing/contrib/rake/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/rake/configuration/settings.rb @@ -14,18 +14,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :quantize, default: {} @@ -37,7 +43,7 @@ class Settings < Contrib::Configuration::Settings # causing undue memory accumulation, as the trace for such tasks is never flushed. option :tasks do |o| o.default { [] } - o.lazy + o.on_set do |value| # DEV: It should be possible to modify the value after it's set. E.g. for normalization. options[:tasks].instance_variable_set(:@value, value.map(&:to_s).to_set) diff --git a/lib/datadog/tracing/contrib/redis/configuration/settings.rb b/lib/datadog/tracing/contrib/redis/configuration/settings.rb index cfddc2c2d4d..d723615458a 100644 --- a/lib/datadog/tracing/contrib/redis/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/redis/configuration/settings.rb @@ -12,33 +12,41 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :command_args do |o| - o.default { env_to_bool(Ext::ENV_COMMAND_ARGS, true) } - o.lazy + o.env_var Ext::ENV_COMMAND_ARGS + o.setter do |value| + val_to_bool(value) + end end option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end end end diff --git a/lib/datadog/tracing/contrib/resque/configuration/settings.rb b/lib/datadog/tracing/contrib/resque/configuration/settings.rb index 35f5083bbce..d2cc6f24e0e 100644 --- a/lib/datadog/tracing/contrib/resque/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/resque/configuration/settings.rb @@ -13,18 +13,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb b/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb index 1bd80b7659c..a5e88d3258c 100644 --- a/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb @@ -12,30 +12,36 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true option :service_name do |o| - o.default do + o.env_var Ext::ENV_SERVICE_NAME + o.setter do |value| Contrib::SpanAttributeSchema.fetch_service_name( - Ext::ENV_SERVICE_NAME, + value, Ext::DEFAULT_PEER_SERVICE_NAME ) end - o.lazy end option :split_by_domain, default: false diff --git a/lib/datadog/tracing/contrib/roda/configuration/settings.rb b/lib/datadog/tracing/contrib/roda/configuration/settings.rb index 3e3b974c8ad..82dbda5a2d1 100644 --- a/lib/datadog/tracing/contrib/roda/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/roda/configuration/settings.rb @@ -11,18 +11,24 @@ module Configuration # Custom settings for the Roda integration class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb b/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb index 28fcdea6999..d7b0b72c69c 100644 --- a/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb @@ -12,8 +12,10 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end end end diff --git a/lib/datadog/tracing/contrib/sequel/configuration/settings.rb b/lib/datadog/tracing/contrib/sequel/configuration/settings.rb index f8c05d67411..72accb45809 100644 --- a/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/sequel/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end end end diff --git a/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb b/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb index 757bc3fe387..57621a11738 100644 --- a/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb @@ -13,18 +13,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb b/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb index 1265de062de..5e4d69a476f 100644 --- a/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb @@ -13,23 +13,31 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :tag_args do |o| - o.default { env_to_bool(Ext::ENV_TAG_JOB_ARGS, false) } - o.lazy + o.env_var Ext::ENV_TAG_JOB_ARGS + o.setter do |value| + val_to_bool(value) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb b/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb index ba514cc35d9..5f357638991 100644 --- a/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb @@ -14,18 +14,24 @@ class Settings < Contrib::Configuration::Settings }.freeze option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :distributed_tracing, default: true diff --git a/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb b/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb index c61883fcc90..c1514dfd0b1 100644 --- a/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb @@ -11,18 +11,24 @@ module Configuration # Default settings for the Shoryuken integration class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/lib/datadog/tracing/contrib/stripe/configuration/settings.rb b/lib/datadog/tracing/contrib/stripe/configuration/settings.rb index c0b656a584a..b17856fe040 100644 --- a/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/stripe/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end end end diff --git a/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb b/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb index ea525ea0736..e0ecb9edbd5 100644 --- a/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb @@ -12,18 +12,24 @@ module Configuration # @public_api class Settings < Contrib::Configuration::Settings option :enabled do |o| - o.default { env_to_bool(Ext::ENV_ENABLED, true) } - o.lazy + o.env_var Ext::ENV_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_enabled do |o| - o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_ENABLED + o.setter do |value| + val_to_bool(value) + end end option :analytics_sample_rate do |o| - o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } - o.lazy + o.env_var Ext::ENV_ANALYTICS_SAMPLE_RATE + o.setter do |value| + val_to_float(value, 1.0) + end end option :service_name diff --git a/sig/datadog/core/environment/variable_helpers.rbs b/sig/datadog/core/environment/variable_helpers.rbs index 1bbf6bcb8ed..a052a35fa93 100644 --- a/sig/datadog/core/environment/variable_helpers.rbs +++ b/sig/datadog/core/environment/variable_helpers.rbs @@ -4,13 +4,13 @@ module Datadog module VariableHelpers extend ::Datadog::Core::Environment::VariableHelpers - def env_to_bool: (untyped var, ?untyped? default) -> untyped + def val_to_bool: (untyped var, ?untyped? default) -> untyped - def env_to_int: (untyped var, ?untyped? default) -> untyped + def val_to_int: (untyped var, ?untyped? default) -> untyped - def env_to_float: (untyped var, ?untyped? default) -> untyped + def val_to_float: (untyped var, ?untyped? default) -> untyped - def env_to_list: (untyped var, ?untyped default) -> untyped + def val_to_list: (untyped var, ?untyped default) -> untyped private diff --git a/spec/datadog/core/configuration/settings_spec.rb b/spec/datadog/core/configuration/settings_spec.rb index c412e849773..76ad1974797 100644 --- a/spec/datadog/core/configuration/settings_spec.rb +++ b/spec/datadog/core/configuration/settings_spec.rb @@ -516,7 +516,7 @@ it 'logs a warning informing customers this has been deprecated for removal' do expect(Datadog.logger).to receive(:warn).with(/deprecated for removal/) - settings.profiling.advanced.force_enable_legacy_profiler = 1234 + settings.profiling.advanced.force_enable_legacy_profiler = true end context 'when value is set to false' do @@ -1238,7 +1238,7 @@ context 'is not defined' do let(:env_var_value) { nil } - it { is_expected.to be 60 } + it { is_expected.to be 60.0 } end context 'is defined' do diff --git a/spec/datadog/core/environment/variable_helpers_spec.rb b/spec/datadog/core/environment/variable_helpers_spec.rb index c5612543ef1..801ef8816d9 100644 --- a/spec/datadog/core/environment/variable_helpers_spec.rb +++ b/spec/datadog/core/environment/variable_helpers_spec.rb @@ -48,8 +48,8 @@ # rubocop:enable RSpec/NamedSubject end - describe '::env_to_bool' do - subject(:env_to_bool) { variable_helpers.env_to_bool(var, **options) } + describe '::val_to_bool' do + subject(:val_to_bool) { variable_helpers.val_to_bool(var) } context 'when env var is not defined' do context 'and default is not defined' do @@ -57,7 +57,7 @@ end context 'and default is defined' do - subject(:env_to_bool) { variable_helpers.env_to_bool(var, default) } + subject(:val_to_bool) { variable_helpers.val_to_bool(var) } let(:default) { double } @@ -101,8 +101,8 @@ end end - describe '::env_to_int' do - subject(:env_to_int) { variable_helpers.env_to_int(var, **options) } + describe '::val_to_int' do + subject(:val_to_int) { variable_helpers.val_to_int(var, **options) } context 'when env var is not defined' do context 'and default is not defined' do @@ -110,7 +110,7 @@ end context 'and default is defined' do - subject(:env_to_int) { variable_helpers.env_to_int(var, default) } + subject(:val_to_int) { variable_helpers.val_to_int(var, default) } let(:default) { double } @@ -149,8 +149,8 @@ end end - describe '::env_to_float' do - subject(:env_to_float) { variable_helpers.env_to_float(var, **options) } + describe '::val_to_float' do + subject(:val_to_float) { variable_helpers.val_to_float(var, **options) } context 'when env var is not defined' do context 'and default is not defined' do @@ -158,7 +158,7 @@ end context 'and default is defined' do - subject(:env_to_float) { variable_helpers.env_to_float(var, default) } + subject(:val_to_float) { variable_helpers.val_to_float(var, default) } let(:default) { double } @@ -197,8 +197,8 @@ end end - describe '::env_to_list' do - subject(:env_to_list) { variable_helpers.env_to_list(var, comma_separated_only: false, **options) } + describe '::val_to_list' do + subject(:val_to_list) { variable_helpers.val_to_list(var, comma_separated_only: false, **options) } context 'when env var is not defined' do context 'and default is not defined' do @@ -206,7 +206,7 @@ end context 'and default is defined' do - subject(:env_to_list) { variable_helpers.env_to_list(var, default, comma_separated_only: false) } + subject(:val_to_list) { variable_helpers.val_to_list(var, default, comma_separated_only: false) } let(:default) { double } @@ -272,7 +272,7 @@ end context 'and comma_separated_only is set' do - subject(:env_to_list) { variable_helpers.env_to_list(var, comma_separated_only: true) } + subject(:val_to_list) { variable_helpers.val_to_list(var, comma_separated_only: true) } context 'value with space' do let(:env_value) { 'value with space' }