diff --git a/lib/datadog/statsd/serialization/stat_serializer.rb b/lib/datadog/statsd/serialization/stat_serializer.rb index 9b75a24..c8e9bcb 100644 --- a/lib/datadog/statsd/serialization/stat_serializer.rb +++ b/lib/datadog/statsd/serialization/stat_serializer.rb @@ -37,9 +37,18 @@ def global_tags attr_reader :prefix attr_reader :tag_serializer - def formatted_metric_name(metric_name) - formatted = Symbol === metric_name ? metric_name.name : metric_name.to_s + if RUBY_VERSION < '3' + def metric_name_to_string(metric_name) + metric_name.to_s + end + else + def metric_name_to_string(metric_name) + Symbol === metric_name ? metric_name.name : metric_name.to_s + end + end + def formatted_metric_name(metric_name) + formatted = metric_name_to_string(metric_name) if formatted.include?('::') formatted = formatted.gsub('::', '.') formatted.tr!(':|@', '_') diff --git a/spec/statsd/serialization/stat_serializer_spec.rb b/spec/statsd/serialization/stat_serializer_spec.rb index 939a0e5..894e79d 100644 --- a/spec/statsd/serialization/stat_serializer_spec.rb +++ b/spec/statsd/serialization/stat_serializer_spec.rb @@ -108,6 +108,18 @@ expect(input).to eq 'somecount:|@test' end end + + context "when metric name is a symbol" do + it 'formats correctly without error' do + input = :'somecount::test' + output = subject.format(input, 1, 'c') + expect(output).to eq 'somecount.test:1|c' + + input = :'somecount:|@test' + output = subject.format(input, 1, 'c') + expect(output).to eq 'somecount___test:1|c' + end + end end context 'benchmark' do