Skip to content

Fix W3CBaggagePropagator to allow empty baggage values per W3C spec#8468

Merged
jkwatson merged 3 commits into
open-telemetry:mainfrom
dahyvuun:fix/w3c-baggage-empty-value
Jul 6, 2026
Merged

Fix W3CBaggagePropagator to allow empty baggage values per W3C spec#8468
jkwatson merged 3 commits into
open-telemetry:mainfrom
dahyvuun:fix/w3c-baggage-empty-value

Conversation

@dahyvuun

Copy link
Copy Markdown
Contributor

Fixes #8465

W3CBaggagePropagator drops baggage entries with empty values like key1=, but the W3C spec defines value = *baggage-octet, meaning zero characters is valid.

.NET, Go, and Rust implementations already accept empty values — Java was the only outlier.

Changes

  • Added allowEmpty flag to Element.createValueElement() to permit empty string values
  • Added seenWhitespace tracking to distinguish key= (valid) from key= (invalid)
  • Updated tests accordingly

@dahyvuun
dahyvuun requested a review from a team as a code owner June 10, 2026 14:48
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 10, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: dahyvuun / name: dahyvuun (8b5d88a)

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.54%. Comparing base (05dfe4e) to head (18eea53).
⚠️ Report is 55 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8468      +/-   ##
============================================
+ Coverage     91.00%   91.54%   +0.54%     
- Complexity     7817    10261    +2444     
============================================
  Files           893     1013     +120     
  Lines         23721    27106    +3385     
  Branches       2364     3183     +819     
============================================
+ Hits          21588    24815    +3227     
- Misses         1410     1565     +155     
- Partials        723      726       +3     

☔ View full report in Codecov by Harness.
📢 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.

Comment thread api/all/src/main/java/io/opentelemetry/api/baggage/propagation/Element.java Outdated

private final BitSet excluded;
private boolean allowEmpty;
private boolean seenWhitespace;

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 think we want to get rid of this, as right now we are accepting key1= but dropping key1= . The spec says:

Leading and trailing whitespaces (OWS) are allowed and are not considered to be a part of the value.

So i think this test needs to no longer return empty()

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.

this is still not addressed. You can remove this entire seenWhitespace variable and related code branches, and then the extract_value_onlySpaces test needs to be updated to:

  @Test
  void extract_value_onlySpaces() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();

    Context result =
        propagator.extract(Context.root(), ImmutableMap.of("baggage", "key1=     "), getter);
    Baggage expectedBaggage =
        Baggage.builder().put("key1", "").build();
    assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
  }

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.

this is what I'm suggesting: dahyvuun#1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 18eea53. Thanks for the example PR!

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome.

For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question.

Automation flags a PR for human review once every review thread has a reply or is marked as resolved.

Status across open PRs is visible on the pull request dashboard.

@jkwatson
jkwatson merged commit 048bbf5 into open-telemetry:main Jul 6, 2026
28 checks passed
@otelbot

otelbot Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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

@dahyvuun
dahyvuun deleted the fix/w3c-baggage-empty-value branch July 6, 2026 16:38
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.

W3CBaggagePropagator drops valid empty baggage values

4 participants