Skip to content

Introduce UserAgent field to allow overriding the default gRPC user-agent string. - #14699

Merged
mx-psi merged 1 commit into
open-telemetry:mainfrom
57Ajay:fix/otlp-grpc-user-agent-override
Apr 24, 2026
Merged

Introduce UserAgent field to allow overriding the default gRPC user-agent string.#14699
mx-psi merged 1 commit into
open-telemetry:mainfrom
57Ajay:fix/otlp-grpc-user-agent-override

Conversation

@57Ajay

@57Ajay 57Ajay commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

fixes #14686

Problem

When a user wants to override the User-Agent sent by the otlp (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.go unconditionally passes the builtin
agent to grpc.WithUserAgent() as a dial option:

agentOpt := configgrpc.WithGrpcDialOption(grpc.WithUserAgent(e.userAgent))

grpc.WithUserAgent() sets the User-Agent at the HTTP/2 transport level, which
takes precedence over any per-call metadata headers — so even if a user sets
User-Agent via headers:, the transport-level value wins and the user's value
is silently discarded.

Fix

Following review feedback from @bogdandrutu and @dmathieu, instead of
fixing this only inside otlpexporter, the fix is applied universally in
configgrpc.ClientConfig so that all gRPC components benefit:

  1. New UserAgent field on ClientConfig (mapstructure:"user_agent,omitempty")
    — a dedicated, first-class config knob for overriding the default gRPC user-agent.

  2. Wiring in getGrpcDialOptions — when cc.UserAgent is set, a
    grpc.WithUserAgent(cc.UserAgent) dial option is appended after extraOpts.
    This ensures it takes precedence over the default BuildInfo-derived string that
    otlpexporter passes via extraOpts, since gRPC-Go applies dial options
    sequentially (last WithUserAgent wins).

  3. No changes to otlp.go — the exporter continues passing the BuildInfo
    string as the default via extraOpts. When a user sets user_agent: in their
    config, configgrpc appends it last and it naturally overrides the default.

Usage

exporters:
  otlp:
    endpoint: "0.0.0.0:4444"
    user_agent: "My Distribution For The Collector"
    tls:
      insecure: true

Testing

  • TestGrpcClientUserAgent in configgrpc_test.go — verifies that setting
    UserAgent on ClientConfig produces the expected dial option in
    getGrpcDialOptions.

  • TestUserAgentHeader_OverriddenByConfig in otlp_test.go — end-to-end test
    that 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
    BuildInfo agent string does not.

@57Ajay
57Ajay requested a review from a team as a code owner March 4, 2026 15:16
@57Ajay
57Ajay requested a review from codeboten March 4, 2026 15:16
@57Ajay
57Ajay force-pushed the fix/otlp-grpc-user-agent-override branch from faeadba to 29feec7 Compare March 6, 2026 05:10
Comment thread config/configgrpc/configgrpc.go Outdated
Comment thread exporter/otlpexporter/otlp.go Outdated
Comment thread exporter/otlpexporter/otlp_test.go
@codecov

codecov Bot commented Mar 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.39%. Comparing base (1cf90bc) to head (d2fe202).
⚠️ Report is 157 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@57Ajay
57Ajay force-pushed the fix/otlp-grpc-user-agent-override branch 2 times, most recently from 28b6e34 to 195ef6b Compare March 6, 2026 10:50
@codspeed-hq

codspeed-hq Bot commented Mar 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 7 untouched benchmarks
⏩ 76 skipped benchmarks1


Comparing 57Ajay:fix/otlp-grpc-user-agent-override (d2fe202) with main (7cd8f58)

Open in CodSpeed

Footnotes

  1. 76 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@57Ajay

57Ajay commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

/rerun

Comment thread config/configgrpc/configgrpc.go
@57Ajay

57Ajay commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

/rerun

1 similar comment
@57Ajay

57Ajay commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

/rerun

@57Ajay
57Ajay force-pushed the fix/otlp-grpc-user-agent-override branch 2 times, most recently from 8636717 to c526ef4 Compare March 16, 2026 14:34
@57Ajay
57Ajay force-pushed the fix/otlp-grpc-user-agent-override branch from c526ef4 to d2fe202 Compare March 16, 2026 14:35
@XuechunHou

Copy link
Copy Markdown

@bogdandrutu A gentle ping to review and approve the PR, thanks

@dmathieu dmathieu added the ready-to-merge Code review completed; ready to merge by maintainers label Apr 13, 2026
@XuechunHou

Copy link
Copy Markdown

Can this be merged please?

@mx-psi

mx-psi commented Apr 22, 2026

Copy link
Copy Markdown
Member

I will merge this by EOW unless there are blocking comments by then cc @bogdandrutu

@bogdandrutu bogdandrutu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@braydonk

braydonk commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 User-Agent header in the headers config (which is actually ignored, and the PR was originally "fixing" that), but the idea pivoted after Damien's comment on the issue to the current state of using a config field.

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 [pkg/config/configgrpc] and the title should say what's in the note section. (Or perhaps someone with permissions on the repo can make that adjustment, I think it's non-controversial)

@dmathieu dmathieu changed the title [exporter/otlp]: fix User-Agent header being ignored in gRPC exporter [exporter/otlp]: Add UserAgent field to allow overriding the default gRPC user-agent string. Apr 23, 2026
@dmathieu dmathieu changed the title [exporter/otlp]: Add UserAgent field to allow overriding the default gRPC user-agent string. Introduce UserAgent field to allow overriding the default gRPC user-agent string. Apr 23, 2026
@mx-psi
mx-psi added this pull request to the merge queue Apr 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 24, 2026
@mx-psi
mx-psi enabled auto-merge April 24, 2026 10:49
@mx-psi
mx-psi added this pull request to the merge queue Apr 24, 2026
Merged via the queue into open-telemetry:main with commit 77ae328 Apr 24, 2026
88 of 90 checks passed
@otelbot

otelbot Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution @57Ajay! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exporter/otlp ready-to-merge Code review completed; ready to merge by maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot configure UserAgent when using oltp grpc exporter

8 participants