Skip to content

fix(ddtrace/tracer): honor DD_DOGSTATSD_PORT over agent StatsD port#4564

Closed
SergioChan wants to merge 1 commit intoDataDog:mainfrom
SergioChan:fix/issue-4518-worker3
Closed

fix(ddtrace/tracer): honor DD_DOGSTATSD_PORT over agent StatsD port#4564
SergioChan wants to merge 1 commit intoDataDog:mainfrom
SergioChan:fix/issue-4518-worker3

Conversation

@SergioChan
Copy link
Copy Markdown

What does this PR do?

  • Updates resolveDogstatsdAddr so an explicitly configured DD_DOGSTATSD_PORT is preserved instead of being overwritten by the agent-reported StatsD port.
  • Keeps existing behavior for UDS and for cases where DD_DOGSTATSD_PORT is not set.
  • Updates TestTracerOptionsDefaults/dogstatsd expectations for env-port and env-all to match the new precedence.
  • Updates the WithDogstatsdAddr docs to reflect the new precedence rule.

Motivation

Issue #4518 reports that DD_DOGSTATSD_PORT is ignored when the agent reports a port, which prevents users from enforcing a different exposed DogStatsD port.

This change gives precedence to explicit DD_DOGSTATSD_PORT configuration while keeping the agent-reported port behavior as the default fallback.

Fixes #4518

Validation:

  • Attempted: go test ./ddtrace/tracer -run "dogstatsd/env-(port|all)$" -count=1
  • Result: not runnable in current upstream state due unrelated compile errors in existing tests (option_test.go / writer_test.go referencing removed config fields like agentURL / traceProtocol).

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.

@SergioChan SergioChan requested a review from a team as a code owner March 19, 2026 17:17
@kakkoyun kakkoyun requested a review from rarguelloF March 20, 2026 11:50
@rarguelloF
Copy link
Copy Markdown
Contributor

@SergioChan thanks so much for the PR!

Sorry it took a little bit longer than expected, but fixing this issue was already in our radar. I went ahead and did a deeper refactor so all the user provided configuration (DD_DOGSTATSD_HOST, DD_DOGSTATSD_PORT and WithDogstatsdAddr) is used before the discovered/default configurations: #4575

@SergioChan
Copy link
Copy Markdown
Author

Thanks for the update and for linking #4575. Since that broader refactor covers this issue path, I’m closing this PR to avoid duplicate work.

@SergioChan
Copy link
Copy Markdown
Author

Closing as superseded by #4575, which applies the user-provided DogStatsD config precedence more comprehensively.

@SergioChan SergioChan closed this Mar 21, 2026
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

2 participants