Skip to content

Commit

Permalink
Added: Deprecation for env when non-string.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed May 14, 2024
1 parent cf264ae commit aea7bc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down
5 changes: 2 additions & 3 deletions spec/datadog/core/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aea7bc9

Please sign in to comment.