Skip to content

feat(baggage)!: add support for w3c baggage#200

Merged
rachelyangdog merged 11 commits into
mainfrom
rachel.yang/w3c-baggage
May 12, 2026
Merged

feat(baggage)!: add support for w3c baggage#200
rachelyangdog merged 11 commits into
mainfrom
rachel.yang/w3c-baggage

Conversation

@rachelyangdog

@rachelyangdog rachelyangdog commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds W3C Baggage propagation support (baggage header) to the composite propagator. When baggage is included in the propagation style configuration, the global TextMapPropagator will read and write the baggage HTTP header using opentelemetry_sdk::propagation::BaggagePropagator.

Changes:

  • Adds TracePropagationStyle::Baggage variant, recognized case-insensitively from DD_TRACE_PROPAGATION_STYLE, DD_TRACE_PROPAGATION_STYLE_EXTRACT, and DD_TRACE_PROPAGATION_STYLE_INJECT

  • Adds baggage to the default propagation styles alongside datadog and tracecontext

  • Wires inject/extract separately at the DatadogPropagator layer, respecting the extract-vs-inject style override independently

  • Adds propagation::baggage module exposing the header key so fields() includes "baggage" when the style is configured

  • system-tests PR

Motivation

What inspired you to submit this pull request?

Additional Notes

  • No new dependencies: opentelemetry_sdk::propagation::BaggagePropagator was already a transitive dependency
  • Baggage propagation is orthogonal to trace context: it operates on OTel Context directly rather than through the internal Propagator trait (which is trace-ID-centric). The Baggage variant's extract/inject arms in that trait are intentional no-ops; the actual work happens one layer up in DatadogPropagator.
  • DD_TRACE_PROPAGATION_STYLE_EXTRACT and DD_TRACE_PROPAGATION_STYLE_INJECT can be used to enable baggage on only one direction independently of the other

@rachelyangdog rachelyangdog requested a review from a team as a code owner March 27, 2026 17:50
@rachelyangdog rachelyangdog marked this pull request as draft March 27, 2026 17:50

@bantonsson bantonsson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good overall

Comment thread datadog-opentelemetry/src/text_map_propagator.rs Outdated
Comment thread datadog-opentelemetry/examples/propagator/src/server.rs Outdated
Comment thread datadog-opentelemetry/src/text_map_propagator.rs Outdated
Comment thread datadog-opentelemetry/src/text_map_propagator.rs Outdated
Comment thread datadog-opentelemetry/src/text_map_propagator.rs
@rachelyangdog rachelyangdog marked this pull request as ready for review April 3, 2026 15:28
Comment thread datadog-opentelemetry/src/text_map_propagator.rs Outdated
Comment thread datadog-opentelemetry/src/text_map_propagator.rs Outdated
Comment thread datadog-opentelemetry/src/text_map_propagator.rs Outdated
Comment thread datadog-opentelemetry/src/text_map_propagator.rs

@iunanua iunanua left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

// propagator *writes*). inner.keys() is extractor-derived, so we strip the baggage key
// from it and re-add it solely based on baggage_inject.
let mut fields: Vec<String> = inner
.keys()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this not using inner.fields()? If there is something wrong with the inner fields then that should be fixed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

By this comment, I have realized we are obtaining inner fields from extractors and as @rachelyangdog says they correspond with the injected headers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's something we inherited from bottlecap 🤔

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Because is the Otel Extrator trait which defines that keys() method
😕

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok, I think get it. They are different things
We have to change the inner fields to fit the injectors.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fix here
Thanks to both of you for bringing this issue to light!

Some(vec![
TracePropagationStyle::Datadog,
TracePropagationStyle::TraceContext,
TracePropagationStyle::Baggage,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since this is a change in behavior, it should be flagged as a breaking change feat(baggage)!:...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should have made this enum #[non_exhaustive] 🫤

@rachelyangdog rachelyangdog changed the title feat(baggage): add support for w3c baggage feat(baggage)!: add support for w3c baggage Apr 30, 2026
# What does this PR do?

- change `DatadogCompositePropagator` to obtain keys from injectors
according to [Otel
spec](https://opentelemetry.io/docs/specs/otel/context/api-propagators/#fields-1).
- remove the not needed `DatadogPropagator::fields` property
@rachelyangdog rachelyangdog merged commit 45dbcc1 into main May 12, 2026
26 checks passed
@rachelyangdog rachelyangdog deleted the rachel.yang/w3c-baggage branch May 12, 2026 16:22
rachelyangdog added a commit that referenced this pull request May 12, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

4 participants