Skip to content

Comply with W3C Baggage specification limits#7880

Merged
pellared merged 23 commits intoopen-telemetry:mainfrom
XSAM:w3c-baggage-compliance
Feb 28, 2026
Merged

Comply with W3C Baggage specification limits#7880
pellared merged 23 commits intoopen-telemetry:mainfrom
XSAM:w3c-baggage-compliance

Conversation

@XSAM
Copy link
Copy Markdown
Member

@XSAM XSAM commented Feb 6, 2026

Updates the baggage implementation to comply with https://www.w3.org/TR/baggage/#limits:

  • Changed maxMembers from 180 to 64 (the W3C compliance requirement)

    The resulting baggage-string contains 64 list-members or less.

  • Removed maxBytesPerMembers (4096) - this per-member limit was not part of the W3C spec

  • Added limit checking in extractMultiBaggage for multiple baggage headers:

    • Checks combined byte size across all headers (max 8192 bytes)
    • Checks combined member count across all headers (max 64 members)

This PR uses non-deterministic truncation when handling baggage limits.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 98.78049% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.7%. Comparing base (7078987) to head (ee28d7a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
propagation/baggage.go 88.8% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7880   +/-   ##
=====================================
  Coverage   81.7%   81.7%           
=====================================
  Files        304     304           
  Lines      23287   23331   +44     
=====================================
+ Hits       19037   19077   +40     
- Misses      3863    3866    +3     
- Partials     387     388    +1     
Files with missing lines Coverage Δ
baggage/baggage.go 99.4% <100.0%> (+<0.1%) ⬆️
internal/errorhandler/errorhandler.go 100.0% <100.0%> (ø)
internal/global/state.go 100.0% <100.0%> (ø)
propagation/baggage.go 95.0% <88.8%> (-5.0%) ⬇️

... and 3 files with indirect coverage changes

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

@XSAM XSAM marked this pull request as ready for review February 6, 2026 02:05
@MrAlias
Copy link
Copy Markdown
Contributor

MrAlias commented Feb 6, 2026

  • Drops all baggage if limits are exceeded per W3C spec

    If a platform cannot propagate all baggage, it MUST NOT propagate any partial list-members"

I don't think dropping all baggage is the correct interpretation of this requirement. We cannot propagate any "partial list-members", but it doesn't mean we cannot propagate complete list-members. Infact, the specification specifically states:

If either of the above conditions is not met, a platform MAY drop list-members until both conditions are met. The selection of which list-members to drop and their order is unspecified and left to the implementer.

While dropping all may indeed be a valid "selection" of list-members, I think we can do better and just take the first, or last n list-members the fit within the limits. Right?

@XSAM
Copy link
Copy Markdown
Member Author

XSAM commented Feb 7, 2026

While dropping all may indeed be a valid "selection" of list-members, I think we can do better and just take the first, or last n list-members the fit within the limits. Right?

Yeah. And, this will need to refactor baggage.Parse.

https://github.com/XSAM/opentelemetry-go/blob/0b29d8f4d883f334ce68981e269d34354ca494e1/baggage/baggage.go#L472

Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Overall this looks good. It addresses the critical security issue, looks W3C specification compliant, and is well tested. The error handling of Parse can be improved, and the issue in extractMultiBaggage, where it silently drops headers, needs to be fixed.

Comment thread propagation/baggage.go Outdated
Comment thread propagation/baggage.go Outdated
Comment thread baggage/baggage.go
Comment thread baggage/baggage.go
Comment thread propagation/baggage.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates OpenTelemetry Go baggage parsing and propagation to enforce W3C Baggage size/member limits (64 members, 8192 bytes) and adjusts tests/changelog accordingly.

Changes:

  • Reduce max baggage members to 64 and remove the per-member byte limit.
  • Apply byte/member limit enforcement while parsing baggage strings and when extracting from multiple baggage headers.
  • Add/adjust unit tests and document the change in the changelog.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
propagation/baggage.go Adds combined multi-header limit handling for member count and total bytes.
propagation/baggage_test.go Adds helper generators and new multi-header limit/behavior test cases.
baggage/baggage.go Updates constants and changes Parse behavior to truncate to W3C limits instead of erroring.
baggage/baggage_test.go Updates tests for new limit behavior and removed per-member limit.
CHANGELOG.md Notes W3C baggage limit compliance changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread propagation/baggage.go Outdated
Comment thread propagation/baggage.go Outdated
Comment thread propagation/baggage_test.go
Comment thread baggage/baggage.go
Comment thread baggage/baggage.go
@dmathieu dmathieu self-requested a review February 17, 2026 15:32
@XSAM XSAM force-pushed the w3c-baggage-compliance branch from 8858ccc to 1b59ccf Compare February 19, 2026 02:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

baggage/baggage_test.go:293

  • Parse now truncates and returns a partial Baggage when the 8192-byte limit is exceeded, but the test cases here no longer cover that behavior (the “too large” case now fails earlier as errInvalidMember). Add a test where the input exceeds maxBytesPerBaggageString after one or more valid members, and assert ErrorIs(err, errBaggageBytes) and that the returned baggage contains the expected prefix members within the byte limit.
func TestBaggageParse(t *testing.T) {
	tooLarge := key(maxBytesPerBaggageString + 1)

	m := make([]string, maxMembers+1)
	for i := range m {
		m[i] = fmt.Sprintf("a%d=", i)
	}
	tooManyMembers := strings.Join(m, listDelimiter)


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread baggage/baggage.go
Comment thread baggage/baggage.go Outdated
Comment thread propagation/baggage.go Outdated
Comment thread propagation/baggage_test.go Outdated
@MrAlias MrAlias added this to the v1.41.0 milestone Feb 19, 2026
@XSAM
Copy link
Copy Markdown
Member Author

XSAM commented Feb 20, 2026

@open-telemetry/go-approvers PTAL

Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Looks great! 🚀

Comment thread baggage/baggage.go Outdated
Comment thread propagation/baggage.go
Comment thread propagation/baggage_test.go Outdated
Comment thread propagation/baggage_test.go Outdated
Comment thread propagation/baggage_test.go Outdated
Comment thread propagation/baggage_test.go Outdated
Copy link
Copy Markdown
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

High-level looks fine to me; I wasn't aware of all the details of the limits so maybe try to over-communicate when this goes out.

@XSAM XSAM requested a review from pellared February 26, 2026 21:14
@pellared pellared merged commit aa1894e into open-telemetry:main Feb 28, 2026
40 of 41 checks passed
@XSAM XSAM deleted the w3c-baggage-compliance branch February 28, 2026 19:16
pellared added a commit that referenced this pull request Mar 2, 2026
This release is the last to support [Go 1.24].
The next release will require at least [Go 1.25].

### Added

- Support testing of [Go 1.26]. (#7902)

### Fixed

- Update `Baggage` in `go.opentelemetry.io/otel/propagation` and `Parse`
and `New` in `go.opentelemetry.io/otel/baggage` to comply with W3C
Baggage specification limits.
`New` and `Parse` now return partial baggage along with an error when
limits are exceeded.
Errors from baggage extraction are reported to the global error handler.
(#7880)

[Go 1.26]: https://go.dev/doc/go1.26
[Go 1.25]: https://go.dev/doc/go1.25
[Go 1.24]: https://go.dev/doc/go1.24
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.

7 participants