Skip to content

fix: strips URI scheme prefixes from DD_DOGSTATSD_URL - #556

Open
hshree-cs wants to merge 1 commit into
mainfrom
GSRE3388/gunicorn
Open

fix: strips URI scheme prefixes from DD_DOGSTATSD_URL#556
hshree-cs wants to merge 1 commit into
mainfrom
GSRE3388/gunicorn

Conversation

@hshree-cs

Copy link
Copy Markdown
Contributor

Fixes metrics error by stripping protocol prefixes (unix://) from DD_DOGSTATSD_URL.

Merge checklist:
Check off if complete or not applicable:

  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

Post-merge:

@hshree-cs
hshree-cs requested a review from a team as a code owner August 12, 2026 09:59
Copilot AI lite review requested due to automatic review settings August 12, 2026 09:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Gunicorn configuration used in containerized deployments to normalize DD_DOGSTATSD_URL into a value suitable for Gunicorn’s StatsD/DogStatsD configuration, aiming to prevent metrics initialization errors when the environment variable includes a URI scheme.

Changes:

  • Adds scheme-stripping/normalization logic for DD_DOGSTATSD_URL before assigning statsd_host.
  • Adds startup logging to record the configured statsd_host.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

import os


logger = logging.getLogger(__name__)
Comment on lines +22 to 33
# Strip protocol schemes so Gunicorn receives the raw file path or HOST:PORT
if _dogstatsd_url.startswith("unix://"):
# Gunicorn accepts unix socket directly as "unix:///path".
_statsd_host = _dogstatsd_url if _dogstatsd_url != "unix://" else ""
_statsd_host = _dogstatsd_url[len("unix://"):]
elif _dogstatsd_url.startswith("unixpack://"):
_statsd_host = _dogstatsd_url[len("unixpack://"):]
elif _dogstatsd_url.startswith("udp://"):
_statsd_host = _dogstatsd_url[len("udp://"):]
else:
# Strip "udp://" when present; Gunicorn expects plain "HOST:PORT".
_statsd_host = (
_dogstatsd_url[len("udp://"):]
if _dogstatsd_url.startswith("udp://")
else _dogstatsd_url
).strip()
_statsd_host = _dogstatsd_url

if _statsd_host:
statsd_host = _statsd_host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants