Skip to content

Add user agent customization#6686

Merged
Kielek merged 20 commits intoopen-telemetry:mainfrom
meijeran:add-user-agent-customization
Dec 4, 2025
Merged

Add user agent customization#6686
Kielek merged 20 commits intoopen-telemetry:mainfrom
meijeran:add-user-agent-customization

Conversation

@meijeran
Copy link
Contributor

Fixes #6496

Design discussion issue #

Changes

Please provide a brief description of the changes here.

This pull request enhances the configuration of the User-Agent HTTP header in the OtlpExporterOptions class, allowing users to prepend custom product identifiers to the default exporter information. It introduces a new property for customization, updates header construction logic, and adds comprehensive tests to ensure correct behavior and compliance with HTTP standards.

User-Agent customization improvements:

  • Added a public UserAgentProductIdentifier property to OtlpExporterOptions that allows users to specify a custom product identifier to be prepended to the default User-Agent header. The header updates dynamically when this property changes.
  • Modified the logic for building the User-Agent string to include the custom identifier, ensuring proper formatting and RFC 7231 compliance (space-separated tokens).
  • Changed StandardHeaders from a static readonly array to a static property backed by a private field, so it reflects the current user agent identifier. [1] [2]

Testing enhancements:

  • Added multiple unit tests in OtlpExporterOptionsTests.cs to verify the default and custom behaviors of the UserAgentProductIdentifier property, including handling of empty/whitespace values, correct header formatting, and compliance with HTTP standards.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • [ X] Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@meijeran meijeran requested a review from a team as a code owner November 12, 2025 10:20
@github-actions github-actions bot added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label Nov 12, 2025
@meijeran meijeran marked this pull request as draft November 12, 2025 10:24
@meijeran meijeran force-pushed the add-user-agent-customization branch from e8fab7f to 3d05c14 Compare November 12, 2025 11:30
meijeran and others added 2 commits November 12, 2025 12:38
@martincostello
Copy link
Member

Looks OK to me now - the maintainers just need to be happy with how it presents as a new public API.

@meijeran meijeran marked this pull request as ready for review November 12, 2025 16:39
Co-authored-by: Martin Costello <martin@martincostello.com>
@rajkumar-rangaraj
Copy link
Member

@meijeran The directions look good. Could you please resolve the build issue? Also, please make sure not to include any unrelated changes in this PR.

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.81%. Comparing base (b0b4211) to head (c89b979).
⚠️ Report is 15 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6686      +/-   ##
==========================================
+ Coverage   86.77%   86.81%   +0.04%     
==========================================
  Files         258      258              
  Lines       11990    11993       +3     
==========================================
+ Hits        10404    10412       +8     
+ Misses       1586     1581       -5     
Flag Coverage Δ
unittests-Project-Experimental 86.67% <100.00%> (-0.10%) ⬇️
unittests-Project-Stable 86.74% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...orter.OpenTelemetryProtocol/OtlpExporterOptions.cs 99.11% <100.00%> (+0.02%) ⬆️
...TelemetryProtocol/OtlpExporterOptionsExtensions.cs 98.95% <100.00%> (ø)

... and 2 files with indirect coverage changes

@Kielek Kielek added this pull request to the merge queue Dec 4, 2025
Merged via the queue into open-telemetry:main with commit a685fee Dec 4, 2025
54 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Thank you for your contribution @meijeran! 🎉 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

pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature request] OTLPExportert - User-Agent customisation

5 participants