@@ -645,6 +645,36 @@ def enqueue_and_process(adapter_skipped:)
645645 context "with sidekiq propagate_traces = false" do
646646 before { Sentry . configuration . sidekiq . propagate_traces = false }
647647
648+ context "when the job generates outgoing trace headers" do
649+ let ( :parity_job ) do
650+ stub_const ( "PropagatingParityJob" , Class . new ( ActiveJob ::Base ) do
651+ self . queue_adapter = :sidekiq
652+ queue_as :events
653+
654+ def perform ( *)
655+ Sentry . capture_message ( "outgoing headers" , extra : { headers : Sentry . get_trace_propagation_headers } )
656+ end
657+ end )
658+ end
659+
660+ it "uses the new consumer transaction's trace without changing the propagation setting" do
661+ enqueued = enqueue ( adapter_skipped : false )
662+
663+ expect ( enqueued . pushed_job ) . not_to have_key ( "trace_propagation_headers" )
664+ expect ( enqueued . pushed_job [ "args" ] . first . dig ( "_sentry" , "trace_propagation_headers" ) ) . to be_nil
665+
666+ events = process ( enqueued . pushed_job , adapter_skipped : false )
667+ transaction = consumer_transactions ( events ) . first
668+ event = events . grep ( Sentry ::ErrorEvent ) . find { |entry | entry . message == "outgoing headers" }
669+ headers = event . extra [ :headers ]
670+ consumer_trace_id = transaction . contexts . dig ( :trace , :trace_id )
671+
672+ expect ( consumer_trace_id ) . not_to eq ( enqueued . parent . trace_id )
673+ expect ( headers [ "sentry-trace" ] . split ( "-" ) . first ) . to eq ( consumer_trace_id )
674+ expect ( headers [ "baggage" ] ) . to include ( "sentry-trace_id=#{ consumer_trace_id } " )
675+ end
676+ end
677+
648678 it "starts a new trace for the job whether the adapter is skipped or not" do
649679 [ true , false ] . each do |adapter_skipped |
650680 enqueued , transaction = enqueue_and_process ( adapter_skipped : adapter_skipped )
0 commit comments