Skip to content

Custom baggage is overwritten with Sentry values #2190

@hasier

Description

@hasier

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.26.0

Steps to Reproduce

Currently, any library that is patched by Sentry tries to append the baggage header whenever possible, e.g, httpx. We currently send our own values within the header. However, when bumping to 1.26.0, we noticed that our headers are being overwritten when using httpx. By debugging some of our calls, I think it has something to do with the way the baggage is calculated here, which seems to only take into account the Sentry DSC, and then it is directly written here in the headers instead of merged with the original value. My feeling is that this is assuming the baggage is injected by OpenTelemetry only (which potentially happens afterwards, but maybe not always?) and won't come as a raw value in the headers.

You should be able to reproduce it as:

  • Initialise a project with sentry-sdk==1.26.0 and httpx
  • Initialise sentry as sentry_sdk.init(default_integrations=True, auto_enabling_integrations=True)
  • Make a call with a httpx client as client.get("/path", headers={"baggage": "custom=value"}) (I used https://webhook.site as the destination to see the actual headers)

You should be able to see how the destination of the call won't receive the original custom=value in the baggage. If you can confirm this, I have also seen other integrations using a similar approach to what the httpx one does, so depending on where the fix needs to happen, other integrations might need amending too.

Expected Result

The Sentry baggage is appended to the custom baggage.

Actual Result

Sentry baggage overwrites the whole baggage value, leaving Sentry values only.

Metadata

Metadata

Assignees

Labels

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions