DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
609 stars 302 forks source link

Dogstatsd doesn't respect statsd_host/statsd_port configuration in initialize func #706

Closed kellanburket closed 2 years ago

kellanburket commented 2 years ago

According to the Dogstatsd documentation, Datadog needs to be initialized with statsd_host and statsd_port configuration. However, this isn't actually a requirement to submit metrics to statsd. Furthermore, the initialize function doesn't respect the statsd_host and statsd_port configurations.

datadog.statsd is really an alias for Dogstatsd(), which initializes statsd with localhost:8125 unless you set the environment variables DD_AGENT_HOST and DD_DOGSTATSD_PORT, which isn't mentioned anywhere in the existing documentation.

This is a real problem for users of datadog on kubernetes or any setup where metrics aren't submitted over the default host and port.

therve commented 2 years ago

Hi,

datadog.statsd isn't an alias, it's an instance of the DogStatsd class. AFAIK the statsd_host setting works as expected:

>>> import datadog
>>> datadog.initialize(statsd_host="example.com")
>>> datadog.statsd.host
'example.com'

It's indeed not a requirement to pass them, but passing them should work.

There is another documentation page which gives you what you're looking for: https://docs.datadoghq.com/developers/dogstatsd/?tab=hostagent: If you use DogStatsD with the Container Agent or in Kubernetes, you must instantiate the host to which StatsD metrics are forwarded to with the $DD_DOGSTATSD_SOCKET environment variable if using a Unix Domain Socket, or with the $DD_AGENT_HOST environment variable if you are using the host port binding method..