Skip to content

set_propagation_headers overwrites existing baggage header instead of merging #2894

@jakubsomonday

Description

@jakubsomonday

Issue Description

Sentry::Utils::HttpTracing#set_propagation_headers unconditionally overwrites all propagation headers on outgoing HTTP requests using req[k] = v. While this is fine for the Sentry-specific sentry-trace header, the baggage header is a W3C standard shared across multiple systems. Any pre-existing baggage entries (e.g. set by OpenTelemetry, application code, or other instrumentation) are silently discarded.

The affected code is in sentry-ruby/lib/sentry/utils/http_tracing.rb#L14-L16:

def set_propagation_headers(req)
  Sentry.get_trace_propagation_headers&.each { |k, v| req[k] = v }
end

Reproduction Steps

  1. Set a custom baggage header on an outgoing HTTP request (e.g. routingKey=myvalue)
  2. Ensure propagate_traces is enabled in Sentry config and the target URL matches trace_propagation_targets
  3. Make the HTTP request using Net::HTTP, Faraday, or Excon
  4. Inspect the outgoing request headers
require "net/http"

Sentry.init do |config|
  config.dsn = "https://key@sentry.io/1"
  config.traces_sample_rate = 1.0
  config.propagate_traces = true
end

uri = URI("https://example.com/api")
req = Net::HTTP::Get.new(uri)
req["baggage"] = "routingKey=myvalue,tenantId=123"

# After Sentry instruments this request, the baggage header
# will only contain sentry-* entries -- the original values are lost
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }

Expected Behavior

When a baggage header already exists on the outgoing request, Sentry should merge its entries with the existing value by joining them with a comma (,), as per the W3C Bagga
ge specification. The resulting header should look like:

sentry-trace_id=abc123,sentry-environment=production,routingKey=myvalue,tenantId=123

Actual Behavior

Sentry replaces the entire baggage header with only Sentry's entries. The resulting header contains:

sentry-trace_id=abc123,sentry-environment=production,sentry-release=xyz,sentry-public_key=key123

The original routingKey=myvalue,tenantId=123 entries are lost.

Ruby Version

All (not version-specific)

SDK Version

All current versions (verified on 6.5.0)

Integration and Its Version

No response

Sentry Config

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions