DataDog / datadogpy

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

Support the standard DD_DOGSTATSD_URL environment variable #805

Open andrewthauer opened 9 months ago

andrewthauer commented 9 months ago

Note:

Is your feature request related to a problem? Please describe.

Currently the only way to configure a connection to a unix domain socket requires doing this in code for every application.

Some of the other Datadog dogstatsd libraries support the DD_DOGSTATSD_URL environment variable for setting either host/port or a unix domain socket. For example https://github.com/DataDog/dogstatsd-ruby gem does this. Also the Datadog Kubernetes operator also automatically adds the DD_DOGSTATSD_URL environment variable to a mounted socket into all pods.

Describe the solution you'd like

This library should support reading the DD_DOGSTATSD_URL environment variable to configure either host/port or unix domain sockets. This will allow configuration outside of code and be consistent with other dogstatsd libraries.

Describe alternatives you've considered

Continue setting this in code and therefore being inconsistent with other Datadog libraries.

Additional context Add any other context or screenshots about the feature request here.

github-actions[bot] commented 8 months ago

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.

andrewthauer commented 8 months ago

Still interested in this!

jianyuan commented 6 months ago

I also agree this would be useful. This functionality is already supported in ddtrace.internal.dogstatsd.get_dogstatsd_client. You can find it here: https://github.com/DataDog/dd-trace-py/blob/fedf88e7161e7eff19038231c2b2fa8f8f75ddec/ddtrace/internal/dogstatsd.py#L9

cdonadeo commented 5 months ago

It may also be worth pointing out that the default behavior for the Admission Controller provided by DataDog/datadog-operator is to mount a Unix domain socket and set DD_DOGSTATSD_URL to unix:///var/run/datadog/dsd.socket inside pods. Making use of that with this Python library involves urllib.parse to check the scheme and then if it is unix:// passing the rest to statsd_socket_path. To handle all valid possibilities, I also need to check for udp:// and set statsd_host and statsd_port based on that.

It's a bit unexpected that Datadog's components aren't better integrated. It's not the worst thing ever, just a bit fussy.

PrayagS commented 3 weeks ago

Bumping this up.

We are facing a situation where we're setting DD_AGENT_HOST for collecting traces but still want to use https://www.github.com/prometheus/statsd_exporter for statsd metrics.

Setting DD_AGENT_HOST overrides it globally and metrics don't work as expected.

A behavior similar to https://www.github.com/DataDog/dd-trace-py would be ideal where DD_DOGSTATSD_URL takes precedence over DD_AGENT_HOST.