Skip to content

fix(ddtrace/tracer): prioritize user-provided settings for dogstatsd addr#4575

Open
rarguelloF wants to merge 5 commits intomainfrom
rarguelloF/dogstatsd-port
Open

fix(ddtrace/tracer): prioritize user-provided settings for dogstatsd addr#4575
rarguelloF wants to merge 5 commits intomainfrom
rarguelloF/dogstatsd-port

Conversation

@rarguelloF
Copy link
Copy Markdown
Contributor

@rarguelloF rarguelloF commented Mar 20, 2026

What does this PR do?

Rewrites resolveDogstatsdAddr to follow a clear, well-defined priority order:

  1. Explicit config (WithDogstatsdAddr) — honored as-is, no overrides.
  2. Dogstatsd-specific env vars (DD_DOGSTATSD_HOST, DD_DOGSTATSD_PORT). DD_AGENT_HOST > localhost is used as a host fallback only when the port is provided and not the host. The agent-reported port > 8125 is used as a fallback when the host is provided but not the port.
  3. Auto-discovery — UDS socket (/var/run/datadog/dsd.socket), then agent-reported port, then localhost:8125. DD_AGENT_HOST is used as the hostname when available.

Motivation

Fix #4518

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running make fix-modules locally.

Unsure? Have a question? Request a review!

@rarguelloF rarguelloF marked this pull request as ready for review March 20, 2026 15:07
@rarguelloF rarguelloF requested a review from a team as a code owner March 20, 2026 15:07
@datadog-official
Copy link
Copy Markdown
Contributor

datadog-official bot commented Mar 20, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 60.03% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 4d40658 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 20, 2026

Benchmarks

Benchmark execution time: 2026-03-26 12:05:07

Comparing candidate commit 4d40658 in PR branch rarguelloF/dogstatsd-port with baseline commit ee1fdc0 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 215 metrics, 9 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Copy link
Copy Markdown
Member

@darccio darccio left a comment

Choose a reason for hiding this comment

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

Approving with a small nit.

@kakkoyun kakkoyun requested review from kakkoyun and mtoffl01 March 23, 2026 10:31
@kakkoyun
Copy link
Copy Markdown
Member

Assigning myself and @mtoffl01 because there were also recent changes touched by us.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.73%. Comparing base (ee1fdc0) to head (4d40658).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/tracer/option.go 85.00% <100.00%> (-2.01%) ⬇️

... and 264 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kakkoyun
Copy link
Copy Markdown
Member

Pinging @mtoffl01 one last time :)

Copy link
Copy Markdown
Contributor

@mtoffl01 mtoffl01 left a comment

Choose a reason for hiding this comment

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

Hmm.. the calls to env.Get("...")...

This is the old way of assuming a configuration can only be set by env var, and later overwritten by programmatic API.

I'd request that for any env var that is already supported in ddtrace/internal/config, get its resolved value from tracer.config.internalConfig instead; for env vars that are not yet supported on that config, it'd be nice if you could add them there, but I guess I won't block this PR on that.

@rarguelloF
Copy link
Copy Markdown
Contributor Author

@mtoffl01 Thanks for the review!

I’d prefer to keep this PR focused on fixing the current behavior in main. Right now main reads these configs using the env package:

func defaultDogstatsdAddr() string {
envHost, envPort := env.Get("DD_DOGSTATSD_HOST"), env.Get("DD_DOGSTATSD_PORT")
if envHost == "" {
envHost = env.Get("DD_AGENT_HOST")
}
if _, err := os.Stat(defaultSocketDSD); err == nil && envHost == "" && envPort == "" {
// socket exists and user didn't specify otherwise via env vars
return "unix://" + defaultSocketDSD
}
host, port := defaultHostname, defaultStatsdPort
if envHost != "" {
host = envHost
}
if envPort != "" {
port = envPort
}
return net.JoinHostPort(host, port)
}
..

Would it be ok to handle these additional changes in a follow-up PR? I think they’re a bit out of scope for this one.

Copy link
Copy Markdown
Contributor

@mtoffl01 mtoffl01 left a comment

Choose a reason for hiding this comment

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

Approved! config migration can happen in a future PR.

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.

[BUG]: DD_DOGSTATSD_PORT env var ignored when agent reports different port

4 participants