Skip to content

Commit

Permalink
Added: Deprecation for service when non-string.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed May 14, 2024
1 parent aea7bc9 commit 8f1430e
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 @@ -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 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
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 @@ -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
Expand Down

0 comments on commit 8f1430e

Please sign in to comment.