Skip to content

opentelemetry-api: make W3CBaggagePropagator compliant with the W3C Baggage spec - #5823

Open
herin049 wants to merge 5 commits into
open-telemetry:mainfrom
herin049:fix/baggage-compliance
Open

herin049 wants to merge 5 commits into
open-telemetry:mainfrom
herin049:fix/baggage-compliance

Conversation

@herin049

@herin049 herin049 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Brings W3CBaggagePropagator in line with the W3C Baggage spec.

Also fixes #5811 and #5566
Closes #5814 #5791

  • Multiple headers: all baggage headers are combined and the limits apply to all of them together.
  • Percent encoding: values use quote/unquote instead of quote_plus/unquote_plus, so + is no longer
    turned into a space.
  • Encoded whitespace: decoded values are no longer stripped, so %20 at either end is kept.
  • Properties: ; properties are validated but no longer stored as part of the value. Before, they were
    re-sent as encoded value data.
  • Keys: keys are treated as tokens. They are not percent-encoded or decoded and invalid keys are skipped
    on inject.
  • Size limits: a header over 8192 bytes no longer drops all baggage. Whole entries are dropped until it fits.
  • Performance: the [ \t]*,[ \t]* split regex took quadratic time on long whitespace runs. It is replaced
    with str.split(","), which also fixes parse_env_headers. Key and value validation now uses character sets
    instead of regexes.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run tox -e typecheck
  • I have run the relevant tests and linting tox environments
  • This requires the following PR in contrib:

@herin049
herin049 requested a review from a team as a code owner October 24, 2026 05:19
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-10-27 00:36 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Oversized incoming headers allocate every split member before limits take effect, causing a verified memory-amplification regression.

1 open issue
What changed in this PR

Updates the API’s W3C baggage propagation to address multiple-header handling (#5811) and percent encoding (#5566), alongside validation and size-limit changes.

Changes:

  • Processes all baggage headers with shared limits and retains entries that fit.
  • Preserves literal + and encoded whitespace, validates token keys, and separates properties from values.
  • Replaces delimiter regex splitting and expands regression coverage.
File Description
opentelemetry-api/​tests/​util/​test_re.py Tests whitespace and empty header members.
opentelemetry-api/​tests/​propagators/​test_w3cbaggagepropagator.py Covers revised extraction, injection, encoding, and limits.
opentelemetry-api/​tests/​baggage/​test_baggage.py Tests character-set validation and property syntax.
opentelemetry-api/​src/​opentelemetry/​util/​re.py Replaces regex-based environment-header splitting.
opentelemetry-api/​src/​opentelemetry/​baggage/​propagation/​__init__.py Updates multi-header parsing, encoding, and key handling.
opentelemetry-api/​src/​opentelemetry/​baggage/​__init__.py Uses character sets for baggage validation.
.changelog/​5823.fixed Records the baggage compliance fixes.

Review effort: Balanced

Comment thread opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py Outdated
Refactor _split_baggage_entries to use find method for splitting headers.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Oct 26, 2026
Comment thread opentelemetry-api/src/opentelemetry/baggage/__init__.py Outdated
@herin049
herin049 requested a review from aabmass October 27, 2026 00:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

W3CBaggagePropagator.extract ignores all but the first baggage header

5 participants