Skip to content

oss_16_baggage_metadata_and_percent_encoding#24

Open
ocelotl wants to merge 2 commits into
mainfrom
oss_16_baggage_metadata_and_percent_encoding
Open

oss_16_baggage_metadata_and_percent_encoding#24
ocelotl wants to merge 2 commits into
mainfrom
oss_16_baggage_metadata_and_percent_encoding

Conversation

@ocelotl

@ocelotl ocelotl commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Closes #20

Preserve W3C Baggage entry metadata and percent-encode spaces as %20 (Linear OSS-16, findings P2/P3). set_baggage gains optional metadata + get_baggage_metadata; propagator splits/re-appends metadata and uses quote/unquote. Validation: api suite 45 passed (baggage+w3c propagator), scope api+changelog. Note: 3 pre-existing tests that asserted the old buggy behavior were updated.

Linear issue: https://linear.app/dash0/issue/OSS-16/p2-p3-w3c-baggage-metadata-dropped-wrong-percent-encoding-vs-percent20

Baggage entry metadata (the ;-delimited properties a W3C Baggage entry may
carry) was previously used only for validation on extract and never stored,
so it was silently dropped and could not be re-injected. set_baggage now
accepts an optional metadata parameter; extract splits the value from its
metadata and stores the metadata alongside the entry, and inject re-appends
it verbatim. A new get_baggage_metadata accessor exposes it.

Spaces were encoded with quote_plus/unquote_plus, emitting a space as + which
spec-compliant receivers misread. Injection and extraction now use
quote/unquote so a space is encoded as %20 per the W3C Baggage format.

Existing set_baggage(name, value) calls are unaffected.
@ocelotl

ocelotl commented Jul 22, 2026

Copy link
Copy Markdown
Owner Author

🔒 Internal (dash0) — not for upstream.

@ocelotl

ocelotl commented Jul 22, 2026

Copy link
Copy Markdown
Owner Author

📣 Public-facing draft — to be used for the upstream PR in open-telemetry/opentelemetry-python. No internal references; copy verbatim.

Title: Preserve W3C Baggage metadata and fix space percent-encoding

What

Fixes two W3C Baggage conformance issues in opentelemetry-api:

  1. Preserve entry metadata. set_baggage accepts an optional metadata: str | None, a new get_baggage_metadata(name, context=None) accessor is added, and W3CBaggagePropagator splits an entry's value from its ;-delimited metadata on extract, stores the metadata, and re-appends it verbatim on inject. Metadata is kept in a separate Context entry, so get_baggage/get_all still return plain string values.
  2. Correct space encoding. Inject/extract use urllib.parse.quote(..., safe="") / unquote instead of quote_plus/unquote_plus, so a space is %20 (per the W3C Baggage format / RFC 3986). safe="" preserves the previous /-escaping.

Why

Metadata was validated then discarded and there was no API to set it, so properties were silently lost (cf. Go baggage.Property, Java BaggageEntryMetadata). quote_plus emitted spaces as +, which compliant receivers misinterpret; the spec requires %20.

Spec

W3C Baggage format: https://www.w3.org/TR/baggage/ · OpenTelemetry Baggage API: specification/baggage/api.md

Tests

New: metadata round-trips extract→inject; metadata via set_baggage is re-appended; no metadata leaves none; overwriting/removing/clearing drops metadata; space injects as %20 and extracts back. Updated 3 pre-existing tests that asserted the old behavior. Full opentelemetry-api suite: 288 passed, 1 skipped.

Backward compatibility

set_baggage(name, value[, context]) unchanged; metadata is a new optional keyword; get_baggage/get_all still return plain values.

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.

oss_16_baggage_metadata_and_percent_encoding

1 participant