From 396e82d0caeb819b9ee8a7721a5ac9bdf40ff4a2 Mon Sep 17 00:00:00 2001 From: David Elner Date: Tue, 14 May 2024 11:21:30 -0400 Subject: [PATCH 1/2] Added: Deprecation for env when non-string. --- lib/datadog/core/configuration/settings.rb | 11 ++++++++++- spec/datadog/core/configuration/settings_spec.rb | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/datadog/core/configuration/settings.rb b/lib/datadog/core/configuration/settings.rb index d3fc59edd75..aac3c1e5fd9 100644 --- a/lib/datadog/core/configuration/settings.rb +++ b/lib/datadog/core/configuration/settings.rb @@ -157,7 +157,16 @@ def initialize(*_) # @return [String,nil] option :env do |o| # DEV-2.0: Remove this conversion for symbol. - o.setter { |v| v.to_s if v } + o.setter do |v| + unless v.nil? || v.is_a?(String) + Datadog::Core.log_deprecation(key: :core_configuration_settings_env_non_string) do + "Use of non-strings for 'env' configuration is deprecated. " \ + 'Use a string instead.' + end + end + + v.to_s if v + end # NOTE: env also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. o.env Core::Environment::Ext::ENV_ENVIRONMENT diff --git a/spec/datadog/core/configuration/settings_spec.rb b/spec/datadog/core/configuration/settings_spec.rb index 96d9137db02..53485f918b4 100644 --- a/spec/datadog/core/configuration/settings_spec.rb +++ b/spec/datadog/core/configuration/settings_spec.rb @@ -230,9 +230,8 @@ context 'when given a symbol' do let(:env) { :symbol } - before { set_env } - - it { expect(settings.env).to eq('symbol') } + it { expect { set_env }.to log_deprecation } + it { expect { set_env }.to change { settings.env }.from(nil).to('symbol') } end context 'when given `nil`' do From 4b44893cac47c1bfbb1ca9b9ec28fff10812d9ba Mon Sep 17 00:00:00 2001 From: David Elner Date: Tue, 14 May 2024 11:29:22 -0400 Subject: [PATCH 2/2] Added: Deprecation for service when non-string. --- lib/datadog/core/configuration/settings.rb | 11 ++++++++++- spec/datadog/core/configuration/settings_spec.rb | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/datadog/core/configuration/settings.rb b/lib/datadog/core/configuration/settings.rb index aac3c1e5fd9..7e4315ab19f 100644 --- a/lib/datadog/core/configuration/settings.rb +++ b/lib/datadog/core/configuration/settings.rb @@ -578,7 +578,16 @@ def initialize(*_) # @return [String] option :service do |o| # DEV-2.0: Remove this conversion for symbol. - o.setter { |v| v.to_s if v } + o.setter do |v| + unless v.nil? || v.is_a?(String) + Datadog::Core.log_deprecation(key: :core_configuration_settings_service_non_string) do + "Use of non-strings for 'service' configuration is deprecated. " \ + 'Use a string instead.' + end + end + + v.to_s if v + end # NOTE: service also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. o.env Core::Environment::Ext::ENV_SERVICE diff --git a/spec/datadog/core/configuration/settings_spec.rb b/spec/datadog/core/configuration/settings_spec.rb index 53485f918b4..958ba33d1ac 100644 --- a/spec/datadog/core/configuration/settings_spec.rb +++ b/spec/datadog/core/configuration/settings_spec.rb @@ -1041,9 +1041,8 @@ context 'when given a symbol' do let(:service) { :symbol } - before { set_service } - - it { expect(settings.service).to eq('symbol') } + it { expect { set_service }.to log_deprecation } + it { expect { set_service }.to change { settings.service }.to('symbol') } end context 'when given `nil`' do