Repository navigation
fix(tracing): drop trailing comma when serializing baggage without third-party items - #8119
Draft
alphasafal wants to merge 1 commit into
Draft
alphasafal wants to merge 1 commit into
alphasafal wants to merge 1 commit into
Conversation
…ird-party items Baggage.serialize(include_third_party=True) appended third_party_items unconditionally, so when there were no third-party items it added an empty segment and the serialized header ended with a comma (e.g. "sentry-trace_id=...,sentry-public_key=...,"). This is reachable from the Celery integration, which calls combined.serialize(include_third_party=True) whenever the merged baggage has only Sentry items. Only append third_party_items when it is non-empty; the output is unchanged when third-party items are present. Adds a regression test.
Author
|
Ran the baggage tests locally against this branch — |
chrikrah
reviewed
Oct 25, 2026
chrikrah
left a comment
There was a problem hiding this comment.
@alphasafal CONTRIBUTING auto-closes outside PRs without a linked, maintainer-acknowledged issue. Otherwise, from my perspective this can be merged at e8f8ace.
# probe_celery.py: _update_celery_task_headers({"baggage": "sentry-trace_id=771a43a4192642f0b136d5159a501700,sentry-sample_rate=0.5"}, span, False)
$ python probe_celery.py # e8f8ace with the base condition (if include_third_party:)
'sentry-trace_id=771a43a4192642f0b136d5159a501700,sentry-sample_rand=0.395125,sentry-environment=production,sentry-transaction=t,sentry-sample_rate=0.5,sentry-sampled=true,'
$ python probe_celery.py # e8f8ace
'sentry-trace_id=771a43a4192642f0b136d5159a501700,sentry-sample_rand=0.051087,sentry-environment=production,sentry-transaction=t,sentry-sample_rate=0.5,sentry-sampled=true'
$ pytest tests/tracing/test_baggage.py tests/integrations/celery/test_update_celery_task_headers.py -q --no-cov
42 passed, 4 warnings in 4.42s # e8f8ace, Python 3.12
1 failed, 41 passed, 4 warnings in 1.11s # base condition restored, test kept
FAILED tests/tracing/test_baggage.py::test_serialize_no_trailing_comma_without_third_party_items
# test_span_with_transaction_custom_headers, the one Celery merge test, sends custom=value
# and expects combined_baggage.serialize(include_third_party=True): it passes on both
non-blocking: add a Celery test without third-party baggage?
Author
alphasafal
marked this pull request as draft
October 26, 2026 02:12
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8120
Summary
Baggage.serialize(include_third_party=True)appendsthird_party_itemsunconditionally. When there are no third-party items (third_party_items == ""), it appends an empty segment, so",".join(...)leaves a trailing comma in the serializedbaggageheader:Per the W3C Baggage spec a trailing comma is an empty list-member (malformed). Sentry's own parser tolerates it, but a strict W3C / OpenTelemetry baggage parser on a downstream consumer can reject or mishandle the header.
Where it's reachable
The Celery integration calls
combined.serialize(include_third_party=True)(sentry_sdk/integrations/celery/__init__.py) when merging incoming and Sentry baggage. Whenever the merged baggage has only Sentry items and no third-party ones — the common Sentry → Celery → Sentry propagation case — the outgoingbaggageheader gets the stray comma.Fix
Only append
third_party_itemswhen it is non-empty:The output is unchanged when third-party items are present.
Test
Adds
test_serialize_no_trailing_comma_without_third_party_itemsintests/tracing/test_baggage.py: it builds a baggage with only Sentry items and asserts the serialized header does not end with,and equals the plainserialize()output. It fails before this change (trailing comma) and passes after.