Shopify / statsd-instrument

A StatsD client for Ruby apps. Provides metaprogramming methods to inject StatsD instrumentation into your code.
http://shopify.github.io/statsd-instrument
MIT License
570 stars 94 forks source link

Datadog format leaves # characters when no labels are set #298

Closed lzap closed 2 years ago

lzap commented 2 years ago

Hey,

we are on an older version of the library and we noticed that the library sends this when there are no labels:

metric.name:1|c|#

Is this expected or a bug? Thanks for help!

Edit: It only happens when I pass tags: [].

lzap commented 2 years ago

Probably not an issue with the current version, closing. Cheers!

diff --git a/test/dogstatsd_datagram_builder_test.rb b/test/dogstatsd_datagram_builder_test.rb
index 181bb05..48e0287 100644
--- a/test/dogstatsd_datagram_builder_test.rb
+++ b/test/dogstatsd_datagram_builder_test.rb
@@ -20,6 +20,16 @@ class DogStatsDDatagramBuilderTest < Minitest::Test
     assert_equal(0, parsed_datagram.value)
   end

+  def test_simple_service_check_empty_array_tags
+    datagram = @datagram_builder._sc("service", :ok, tags: [])
+    assert_equal("_sc|service|0", datagram)
+  end
+
+  def test_simple_service_check_empty_hash_tags
+    datagram = @datagram_builder._sc("service", :ok, tags: {})
+    assert_equal("_sc|service|0", datagram)
+  end
+
   def test_complex_service_check
     datagram = @datagram_builder._sc("service", :warning, timestamp: Time.parse("2019-09-30T04:22:12Z"),
       hostname: "localhost", tags: { foo: "bar|baz" }, message: "blah")