Introduce UserAgent field to allow overriding the default gRPC user-agent string. - #14699
Conversation
faeadba to
29feec7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14699 +/- ##
==========================================
- Coverage 91.85% 91.39% -0.46%
==========================================
Files 685 695 +10
Lines 43391 44392 +1001
==========================================
+ Hits 39855 40572 +717
- Misses 2459 2687 +228
- Partials 1077 1133 +56 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
28b6e34 to
195ef6b
Compare
Merging this PR will not alter performance
|
|
/rerun |
|
/rerun |
1 similar comment
|
/rerun |
8636717 to
c526ef4
Compare
Signed-off-by: 57Ajay <57ajay.u@gmail.com>
c526ef4 to
d2fe202
Compare
|
@bogdandrutu A gentle ping to review and approve the PR, thanks |
|
Can this be merged please? |
|
I will merge this by EOW unless there are blocking comments by then cc @bogdandrutu |
bogdandrutu
left a comment
There was a problem hiding this comment.
I am confused about the title of the PR, it does not fix anything "broken" since this config did not exists, and also it applies to all exportes.
|
I think the title is just out of date compared to feedback on the solution; initial pitch iirc was to have this be set via the I'd edit the title myself but I don't have the permissions on this repo. @57Ajay I would suggest adjusting the title to basically what you have in the changelog here - the component is actually |
77ae328
fixes #14686
Problem
When a user wants to override the
User-Agentsent by theotlp(gRPC) exporter,there is no way to do so. The downstream server always receives the builtin
BuildInfo-derived agent string (e.g.opentelemetry-collector/0.145.0 (linux/amd64)).This is because
exporter/otlpexporter/otlp.gounconditionally passes the builtinagent to
grpc.WithUserAgent()as a dial option:grpc.WithUserAgent()sets theUser-Agentat the HTTP/2 transport level, whichtakes precedence over any per-call metadata headers — so even if a user sets
User-Agentviaheaders:, the transport-level value wins and the user's valueis silently discarded.
Fix
Following review feedback from @bogdandrutu and @dmathieu, instead of
fixing this only inside
otlpexporter, the fix is applied universally inconfiggrpc.ClientConfigso that all gRPC components benefit:New
UserAgentfield onClientConfig(mapstructure:"user_agent,omitempty")— a dedicated, first-class config knob for overriding the default gRPC user-agent.
Wiring in
getGrpcDialOptions— whencc.UserAgentis set, agrpc.WithUserAgent(cc.UserAgent)dial option is appended afterextraOpts.This ensures it takes precedence over the default
BuildInfo-derived string thatotlpexporterpasses viaextraOpts, since gRPC-Go applies dial optionssequentially (last
WithUserAgentwins).No changes to
otlp.go— the exporter continues passing theBuildInfostring as the default via
extraOpts. When a user setsuser_agent:in theirconfig,
configgrpcappends it last and it naturally overrides the default.Usage
Testing
TestGrpcClientUserAgentinconfiggrpc_test.go— verifies that settingUserAgentonClientConfigproduces the expected dial option ingetGrpcDialOptions.TestUserAgentHeader_OverriddenByConfiginotlp_test.go— end-to-end testthat starts a real gRPC server, configures the exporter with a custom
UserAgent,sends metrics, and asserts the custom value reaches the server while the builtin
BuildInfoagent string does not.