Skip to content

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

Open
dahyvuun wants to merge 2 commits into
open-telemetry:mainfrom
dahyvuun:fix/w3c-baggage-empty-value
Open

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

Conversation

@dahyvuun

Copy link
Copy Markdown

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.03%. Comparing base (05dfe4e) to head (7c54f00).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8468      +/-   ##
============================================
+ Coverage     91.00%   91.03%   +0.03%     
- Complexity     7817     7823       +6     
============================================
  Files           893      893              
  Lines         23721    23727       +6     
  Branches       2364     2365       +1     
============================================
+ Hits          21588    21601      +13     
+ Misses         1410     1407       -3     
+ Partials        723      719       -4     

☔ 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);
  }

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

3 participants