Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .with_headers to support multiple k/v pairs #2699

Merged
merged 6 commits into from
Feb 24, 2025

Conversation

joshwlewis
Copy link
Contributor

@joshwlewis joshwlewis commented Feb 21, 2025

Changes

Currently, .with_headers doesn't work consistently when passing in multiple k/v pairs. For instance, something like this only adds one of the headers:

HttpExporterBuilder::default()
    .with_headers(HashMap::from([
        ("k1".to_string(), "v1".to_string()),
        ("k2".to_string(), "v2".to_string()),
    ]))

This is quite surprising -- only one header is actually accepted, and it's a random choice. The others are lost. To work around this with the existing code, add one k/v at a time like this:

HttpExporterBuilder::default()
    .with_headers(HashMap::from([("k1".to_string(), "v1".to_string())]))
    .with_headers(HashMap::from([("k2".to_string(), "v2".to_string())]));

I've updated the tests to cover the surprising scenario, and adjusted the logic to support multiple k/v pairs.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@joshwlewis joshwlewis requested a review from a team as a code owner February 21, 2025 16:29
Copy link

linux-foundation-easycla bot commented Feb 21, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.3%. Comparing base (edab145) to head (2795f2f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2699     +/-   ##
=======================================
- Coverage   79.3%   79.3%   -0.1%     
=======================================
  Files        123     123             
  Lines      22657   22660      +3     
=======================================
+ Hits       17975   17977      +2     
- Misses      4682    4683      +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Thanks! Could you add a one-line to the changelog for this bug fix.

@joshwlewis joshwlewis force-pushed the jwl/fix-multiple-header branch from 31e5439 to 2795f2f Compare February 24, 2025 21:36
@joshwlewis
Copy link
Contributor Author

@cijothomas done. Not sure what the integration tests failure is about, though. Maybe a fluke and worth retrying?

@cijothomas cijothomas merged commit 64549d7 into open-telemetry:main Feb 24, 2025
21 checks passed
@joshwlewis joshwlewis deleted the jwl/fix-multiple-header branch March 19, 2025 20:58
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.

None yet

3 participants