Describe the bug
Using Enum for metric names in the various statsd methods inconsistently converts to underlying str representation
To Reproduce
class MyServiceEvents(str, Enum):
MODEL_UPDATE = "my-service.model-update"
from datadog import statsd
# Shows up in DataDog as event name `MyServiceEvents.MODEL_UPDATE
statsd.increment(MyServiceEvents.MODEL_UPDATE, ...)
# Shows up in DataDog as event name `my-service.model-update`
statsd.event(title=MyServiceEvents.MODEL_UPDATE, ...)
Expected behavior
Expect all statsd functions to exhibit consistent behavior, one way or the other.
Screenshots
N/A
Environment and Versions (please complete the following information):
datadog=0.25.1
Additional context
statsd.increment, .gauge, .foo go through the metrics reporting chain via _report -> _serialize_metric, which creates a metric packet like:
"%s%s:%s|%s%s%s%s%s%s%s" % (
(self.namespace + ".") if self.namespace else "",
metric,
value,
...
so if metric is a string enum there, you're going to get the string enum representation
events go through DogStatsd._escape_event_content(title), which is title.replace("\n", "\\n"). title.replace(...) is inherited from str, so you get a str back, e.g.
class Foo(str, Enum):
x = "x"
abcde = "abcde"
Foo.abcde.replace("abc", "123")
'123de'
even if you replace a substring that's not present, you still change the type from the enum to a string
Foo.abcde.replace("lol", "ohno")
'abcde'
Foo.abcde
<Foo.abcde: 'abcde'>
Describe the bug
Using
Enumfor metric names in the variousstatsdmethods inconsistently converts to underlyingstrrepresentationTo Reproduce
Expected behavior
Expect all statsd functions to exhibit consistent behavior, one way or the other.
Screenshots
N/A
Environment and Versions (please complete the following information):
datadog=0.25.1Additional context
statsd.increment, .gauge, .foo go through the metrics reporting chain via _report -> _serialize_metric, which creates a metric packet like:
so if metric is a string enum there, you're going to get the string enum representation
events go through
DogStatsd._escape_event_content(title), which istitle.replace("\n", "\\n").title.replace(...)is inherited fromstr, so you get astrback, e.g.even if you replace a substring that's not present, you still change the type from the enum to a string