Skip to content

fix: Do not overwrite baggage header contents if it already exists#2896

Merged
solnic merged 1 commit intogetsentry:masterfrom
jakubsomonday:jakubso/fix-baggage-overwrite/1
Mar 18, 2026
Merged

fix: Do not overwrite baggage header contents if it already exists#2896
solnic merged 1 commit intogetsentry:masterfrom
jakubsomonday:jakubso/fix-baggage-overwrite/1

Conversation

@jakubsomonday
Copy link
Contributor

When making outgoing HTTP requests, the SDK was overwriting any pre-existing baggage header on the request with Sentry's own baggage values. This caused loss of third-party baggage entries (e.g., routingKey, tenantId) that were already set on the request.

This fix updates set_propagation_headers to merge Sentry's baggage with any existing baggage on the request instead of replacing it, following the W3C Baggage specification which allows comma-separated list entries from multiple providers.

A similar issue was previously identified and fixed in the Python SDK: getsentry/sentry-python#2191

Changes

  • Modified Sentry::Utils::HttpTracing#set_propagation_headers to check for an existing baggage header and merge values instead of overwriting
  • Added test cases covering both the merge scenario and the default (no pre-existing baggage) scenario

Fixes #2894

@solnic
Copy link
Collaborator

solnic commented Mar 18, 2026

Thank you! I'm gonna merge this in and follow-up with additional features that will ensure we're not exceeding W3C limits with the baggage content 😄

@solnic solnic merged commit ebb05d6 into getsentry:master Mar 18, 2026
258 of 261 checks passed
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.48%. Comparing base (7d10c02) to head (f255cc0).
⚠️ Report is 54 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2896      +/-   ##
==========================================
+ Coverage   90.13%   90.48%   +0.34%     
==========================================
  Files         132      141       +9     
  Lines        5301     5600     +299     
==========================================
+ Hits         4778     5067     +289     
- Misses        523      533      +10     
Components Coverage Δ
sentry-ruby 97.28% <98.31%> (-0.01%) ⬇️
sentry-rails 55.35% <20.00%> (-0.15%) ⬇️
sentry-sidekiq 95.05% <100.00%> (ø)
sentry-resque 94.44% <ø> (ø)
sentry-delayed_job 94.68% <ø> (ø)
sentry-opentelemetry 99.56% <100.00%> (+0.25%) ⬆️
Files with missing lines Coverage Δ
sentry-ruby/lib/sentry/utils/http_tracing.rb 97.43% <100.00%> (+0.21%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

set_propagation_headers overwrites existing baggage header instead of merging

2 participants