Skip to content

Commit

Permalink
Update Statsd tag serializer to allow falsy values
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-hughes committed Dec 12, 2024
1 parent 694f421 commit ad053c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/datadog/statsd/serialization/tag_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def to_tags_list(tags)
case tags
when Hash
tags.map do |name, value|
if value
escape_tag_content("#{name}:#{value}")
else
if value.nil?
escape_tag_content(name)
else
escape_tag_content("#{name}:#{value}")
end
end
when Array
Expand Down
14 changes: 14 additions & 0 deletions spec/statsd/serialization/tag_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@
expect(subject.format([tag])).to eq 'node:storage'
end

it 'ignores hash tag values which are not present when called with to_s' do
message_tags_hash = {
request: [],
missing: nil,
'another' => {},
blank: '',
:yet_another => false,
'results in blank': double('some tag', to_s: ''),
'results in nil': double('some tag', to_s: nil),
}

expect(subject.format(message_tags_hash)).to eq 'request:[],another:{},yet_another:false'
end

it 'formats frozen tags correctly' do
expect(subject.format(['name:foobarfoo'.freeze])).to eq 'name:foobarfoo'
end
Expand Down

0 comments on commit ad053c0

Please sign in to comment.