refactor(config): Migrate agentURL and traceProtocol#4550
Conversation
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 19c01e7 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
Codecov Report❌ Patch coverage is Additional details and impacted files
🚀 New features to boost your workflow:
|
BenchmarksBenchmark execution time: 2026-03-18 15:12:46 Comparing candidate commit 19c01e7 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 155 metrics, 9 unstable metrics.
|
| c.agent.store(af) | ||
| if af.v1ProtocolAvailable { | ||
| c.traceProtocol = traceProtocolV1 | ||
| if !af.v1ProtocolAvailable && c.internalConfig.TraceProtocol() == traceProtocolV1 { |
There was a problem hiding this comment.
This condition is a little confusing. And maybe not correct.
Could this be?
| if !af.v1ProtocolAvailable && c.internalConfig.TraceProtocol() == traceProtocolV1 { | |
| if !af.v1ProtocolAvailable or c.internalConfig.TraceProtocol() == traceProtocolV04 { |
There was a problem hiding this comment.
The condition is correct as written.
Basically:
The resolution logic for user-configured trace protocol now happens exclusively in internal/config. It does not consider agentFeatures, only the user-supplied DD_TRACE_AGENT_PROTOCOL_VERSION or the default fallback (traceProtocolV04):
- Is DD_TRACE_AGENT_PROTOCOL_VERSION set to a valid value? If so, use it.
- Else, fallback to traceProtocolV04
So now, on line 464 we got information about agentfeatures; in the case that a user has said "I want trace protocol v1" but agentfeatures shows that v1 is not available, we force the configuration back to traceProtocolV04.
This is aligned with the old logic, it's just that the old logic did it this way:
- the "v1ProtocolAvailable" flag on agentFeatures was determined by BOTH /v1/info available on agent AND user-configured DD_TRACE_AGENT_PROTOCOL_VERSION=1.0 flag
- therefore, at line 464 of option.go, we were previously only checking af.v1ProtocolAvailable and setting accoridngly; else falling back to v04.
There was a problem hiding this comment.
Thanks for the explanation. I was a little tired when I did the review.
That being said, I think we should add a comment here.
| } | ||
|
|
||
| func validateTraceProtocolVersion(v string) bool { | ||
| return v == "0.4" || v == "1.0" |
There was a problem hiding this comment.
nit: We can use some constants here.
There was a problem hiding this comment.
The constants for these values are currently defined in the tracer package. I originally moved them over here, into config, as public constants then realized that they are most used by tracer. So this looked like lots of references to internalconfig.TraceProtocolV1 instead of just TraceProtocolV1 across the codebase.
My options are:
- re-impliment that
- keep things as is
- import the tracer constants in
config - define a second set of constants in either one of the packages
Any preferences?
There was a problem hiding this comment.
I think we should strike for only having a single source of truth for these. For whatever reason if we decide to change these values, we might forget about them in here. So I'm good with anything that would keep them in sync.
| log.Warn("Failed to parse DD_TRACE_AGENT_URL: %s", err.Error()) | ||
| } else { | ||
| switch u.Scheme { | ||
| case "unix", "http", "https": |
There was a problem hiding this comment.
nit: we can use constants here. Especially give we have some repetitions.
| return &u | ||
| } | ||
|
|
||
| func (c *Config) SetAgentURL(u *url.URL, origin telemetry.Origin) { |
There was a problem hiding this comment.
nit: We can consider making the second argument optional here. And make telemetry.OriginCode as default. Most (if not all) of the call-site uses that as argument.
| func (c *Config) SetAgentURL(u *url.URL, origin telemetry.Origin) { | |
| func (c *Config) SetAgentURL(u *url.URL, origin ...telemetry.Origin) { |
There was a problem hiding this comment.
This is a fabulous suggestion 🙇
There was a problem hiding this comment.
I originally loved this idea because I dislike having to add a "fake" origin in tests when we don't really care about setting the origin.
But as I went to implement this, I realized making origin variadic was even more displeasing to me... 🤔
First of all, it invites providing multiple values for origin, which is a confusing API, and confusing when the function logic has to "choose" a value from the origin list to use as its source of truth (e.g, origin[0]).
An alternative is to provide secondary APIs like SetAgentURLDefault(u *url.URL) which hardcodes the OriginDefeault.
Or, to leave things as they are.
WDYT?
There was a problem hiding this comment.
Yes, unfortunately this is the only optional argument pattern we have in Go. We can explicitly document the behavior here. It's not completely idiomatic but it's very common to use. It's just ergonomics.
That being said, I'm also okay to have methods like SetAgentURLDefault(u *url.URL), I just want to make sure we reduce the possibility of making mistakes here.
There was a problem hiding this comment.
I'm leaving the decision to you.
There was a problem hiding this comment.
Upon review, I don't see any cal sites that actually need "SetAgentURLDefault." However, in general the Config type would benefit from additional methods like SetXDefault that don't require an origin to be passed in. Because it doesn't directly impact this PR, I'll consider this for a follow-up PR.
| c.agent.store(af) | ||
| if af.v1ProtocolAvailable { | ||
| c.traceProtocol = traceProtocolV1 | ||
| if !af.v1ProtocolAvailable && c.internalConfig.TraceProtocol() == traceProtocolV1 { |
There was a problem hiding this comment.
Thanks for the explanation. I was a little tired when I did the review.
That being said, I think we should add a comment here.
bm1549
left a comment
There was a problem hiding this comment.
Approving on behalf of Capabilities since Ben is out
…`traceProtocol` fields (#4565) <!-- * New contributors are highly encouraged to read our [CONTRIBUTING](/CONTRIBUTING.md) documentation. * Commit and PR titles should be prefixed with the general area of the pull request's change. --> ### What does this PR do? Fixes outdated references to `agentURL` and `traceProtocol` fields on the tracer's `config` struct; these fields were removed from the struct in #4550 and replaced by internalConfig access. ### Motivation Fixes bug on main -- [Monitor Alert](https://app.datadoghq.com/monitors/255603167?q=%40git.repository.id_v2%3Agithub.com%2Fdatadog%2Fdd-trace-go&event_id=AwAAAZ0HFd6YboDOBQAAABhBWjBIRjBWMUFBQlNNTHh6bWp4QUVJWTMAAAAkMDE5ZDA3MWMtMGNhMC00MGZiLTgyMTItNTJhOWMwYWVlYzZkAABXMg&link_event_id=8550971062156716057&link_monitor_id=255603167&link_source=monitor_notif&from_ts=1773939467000&to_ts=1773940667000&live=false). ### Reviewer's Checklist <!-- * Authors can use this list as a reference to ensure that there are no problems during the review but the signing off is to be done by the reviewer(s). --> - [ ] Changed code has unit tests for its functionality at or near 100% coverage. - [ ] [System-Tests](https://github.com/DataDog/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!
What does this PR do?
Migrates resolution logic for agentURL and traceProtocol configurations from tracer/option.go into internal/config.
Motivation
Part of config revamp migration.
Reviewer's Checklist
make lintlocally.make testlocally.make generatelocally.make fix-moduleslocally.Unsure? Have a question? Request a review!