From 9668fe6e76b8cff14f4a3380aae212a03ad36108 Mon Sep 17 00:00:00 2001 From: snek Date: Thu, 25 Aug 2022 12:59:16 -0700 Subject: [PATCH 1/2] support dict for event/metric tags --- datadog/dogstatsd/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datadog/dogstatsd/base.py b/datadog/dogstatsd/base.py index 1bdb47f5d..5c7c946eb 100644 --- a/datadog/dogstatsd/base.py +++ b/datadog/dogstatsd/base.py @@ -1026,6 +1026,8 @@ def service_check( self._send(string) def _add_constant_tags(self, tags): + if isinstance(tags, dict): + tags = list(map(lambda kv: '%s:%s' % kv, tags.items())) if self.constant_tags: if tags: return tags + self.constant_tags From 5fce98085ab55b7e6dbd1675e0796e41eaf13f53 Mon Sep 17 00:00:00 2001 From: snek Date: Thu, 25 Aug 2022 13:05:29 -0700 Subject: [PATCH 2/2] Update test_statsd.py --- tests/unit/dogstatsd/test_statsd.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/dogstatsd/test_statsd.py b/tests/unit/dogstatsd/test_statsd.py index 658804a19..2820b2660 100644 --- a/tests/unit/dogstatsd/test_statsd.py +++ b/tests/unit/dogstatsd/test_statsd.py @@ -334,6 +334,10 @@ def test_tagged_histogram(self): self.statsd.histogram('h', 1, tags=['red']) self.assert_equal_telemetry('h:1|h|#red\n', self.recv(2)) + def test_dict_tagged(self): + self.statsd.increment('dct', tags={'country': 'españa'}) + self.assert_equal_telemetry('dct:1|c|#country:españa\n', self.recv(2)) + def test_sample_rate(self): # Disabling telemetry since sample_rate imply randomness self.statsd._telemetry = False