Skip to content

feat(baggage): add support for baggage span tags#223

Open
rachelyangdog wants to merge 21 commits into
mainfrom
rachel.yang/baggage-span-tags
Open

feat(baggage): add support for baggage span tags#223
rachelyangdog wants to merge 21 commits into
mainfrom
rachel.yang/baggage-span-tags

Conversation

@rachelyangdog
Copy link
Copy Markdown
Contributor

@rachelyangdog rachelyangdog commented May 8, 2026

What does this PR do?

Implements the DD_TRACE_BAGGAGE_TAG_KEYS feature, which automatically promotes W3C Baggage entries to span tags at extraction time.

When a span is created with a remote parent, baggage entries matching the configured filter are attached as span attributes prefixed with baggage.:

baggage: user.id=alice,session.id=xyz123
→ span tag baggage.user.id = "alice"
→ span tag baggage.session.id = "xyz123"

Tags are only applied at extraction time, not to locally-created root spans.

Baggage Tagging Behavior

  • "" (empty): Disabled — no baggage keys become span tags
  • "*": All baggage keys are tagged
  • "user.id,session.id": Only the listed keys are tagged
  • (unset): Default is user.id, session.id, account.id

W3C spec compliance fix
Per the W3C Baggage spec, a malformed member (empty key, empty value, or missing =) must cause all subsequent members to be dropped — not just the malformed one. This PR fixes the extraction to use stop-at-first-error semantics instead of skip-and-continue.

  • Before: user.id=,session.id=abc → {session.id: "abc"} (partial extraction)
  • After: user.id=,session.id=abc → {} (entire header dropped after malformed entry)

Configuration

  • Env var: DD_TRACE_BAGGAGE_TAG_KEYS
  • Default: "user.id,session.id,account.id"

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

@rachelyangdog rachelyangdog requested a review from a team as a code owner May 8, 2026 18:22
@rachelyangdog rachelyangdog marked this pull request as draft May 8, 2026 18:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05f787b853

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +572 to +574
for kv in baggage_span_tags(parent_ctx.baggage(), self.config.trace_baggage_tag_keys())
{
span.set_attribute(kv);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Promote baggage tags on baggage-only root spans

When an incoming request carries only a baggage header (or a local root span is started with baggage) and no valid remote trace context, extract_with_context still attaches the baggage to parent_ctx, but this loop only runs inside the is_remote() branch. That makes DD_TRACE_BAGGAGE_TAG_KEYS silently ineffective for baggage-only propagation, even though this change adds baggage as a supported propagation style; the local-root path should also apply these baggage span tags.

Useful? React with 👍 / 👎.

@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 Bot commented May 8, 2026

Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

🧪 1 Test failed

tests.parametric.test_headers_baggage.Test_Headers_Baggage_Span_Tags.test_baggage_span_tags_malformed_header[parametric-rust] from system_tests_suite   View in Datadog   (Fix with Cursor)
AssertionError: assert '' is None
 +  where '' = <built-in method get of dict object at 0x7fd064859880>('baggage.user.id')
 +    where <built-in method get of dict object at 0x7fd064859880> = {'_dd.p.dm': '-0', 'baggage.account.id': 'abcd', 'baggage.session.id': 'mysession', 'baggage.user.id': '', ...}.get

self = <tests.parametric.test_headers_baggage.Test_Headers_Baggage_Span_Tags object at 0x7fd096592180>
test_agent = <utils.docker_fixtures._test_agent.TestAgentAPI object at 0x7fd06411d550>
test_library = <utils.docker_fixtures._test_clients._test_client_parametric.ParametricTestClientApi object at 0x7fd06411f4a0>

    def test_baggage_span_tags_malformed_header(self, test_agent: TestAgentAPI, test_library: APMLibrary) -> None:
        with test_library:
...

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 23d9998 | Docs | Datadog PR Page | Give us feedback!

rachelyangdog and others added 3 commits May 12, 2026 13:00
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Per W3C Baggage spec, a malformed member invalidates the rest of the
header. Change extraction to stop on the first unparseable entry
(including entries with empty keys or values) rather than skipping and
continuing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rachelyangdog rachelyangdog changed the title WIP: feat(baggage): add support for baggage span tags feat(baggage): add support for baggage span tags May 12, 2026
@rachelyangdog rachelyangdog marked this pull request as ready for review May 12, 2026 20:13
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1dd94661a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread datadog-opentelemetry/src/propagation/baggage.rs Outdated
W3C Baggage spec defines value = *baggage-octet (zero or more), so
empty values are valid. Only empty keys are truly malformed
(key = 1*tchar requires at least one character).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread datadog-opentelemetry/src/propagation/baggage.rs
Comment thread datadog-opentelemetry/src/core/configuration/configuration.rs Outdated
Comment thread datadog-opentelemetry/src/propagation/baggage.rs
rachelyangdog and others added 3 commits May 13, 2026 10:58
An input like "," or ", ," produces an empty key list after filtering,
which behaves identically to Disabled. Normalize it explicitly so Keys
always contains at least one entry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Empty values are valid per W3C spec (value = *baggage-octet), so this
test case that was removed when we incorrectly rejected empty values
should be present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ced default

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@iunanua
Copy link
Copy Markdown
Collaborator

iunanua commented May 14, 2026

A ST is failing because it expects all items get dropped if a value is missing 🙃

rachelyangdog and others added 2 commits May 14, 2026 10:43
Points to the updated test_baggage_span_tags_malformed_header which
uses an empty key (=doggo,...) as the malformed case, per W3C spec
(empty values are valid, only empty keys are not).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

3 participants