Skip to content

Commit a024558

Browse files
authored
Fix Sidekiq tracing headers not being overwritten in case of schedules and retries [#2118](#2118) (#2118)
#1774 added `SentryContextClientMiddleware` to the server middleware chain too. Sidekiq's scheduler pushes to the client on the server again for schedules and retries which causes our trace propagation to be broken for this case. https://github.com/sidekiq/sidekiq/blob/aadc77a172f1490fb141c7936d2801ca3af925ef/lib/sidekiq/scheduled.rb#L39 Prioritize taking the trace propagation headers from the job whenever they exist.
1 parent efcc58a commit a024558

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Always send envelope trace header from dynamic sampling context [#2113](https://github.com/getsentry/sentry-ruby/pull/2113)
1414
- Improve `TestHelper`'s setup/teardown helpers ([#2116](https://github.com/getsentry/sentry-ruby/pull/2116))
1515
- Fixes [#2103](https://github.com/getsentry/sentry-ruby/issues/2103)
16+
- Fix Sidekiq tracing headers not being overwritten in case of schedules and retries [#2118](https://github.com/getsentry/sentry-ruby/pull/2118)
1617

1718
## 5.11.0
1819

Diff for: sentry-sidekiq/lib/sentry/sidekiq/sentry_context_middleware.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def call(_worker_class, job, _queue, _redis_pool)
5959

6060
user = Sentry.get_current_scope.user
6161
job["sentry_user"] = user unless user.empty?
62-
job["trace_propagation_headers"] = Sentry.get_trace_propagation_headers
62+
job["trace_propagation_headers"] ||= Sentry.get_trace_propagation_headers
6363
yield
6464
end
6565
end

Diff for: sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,24 @@
129129
expect(headers["sentry-trace"]).to eq(transaction.to_sentry_trace)
130130
expect(headers["baggage"]).to eq(transaction.to_baggage)
131131
end
132+
133+
# sidekiq pushes the same job to the queue again from the server for schedules and retries
134+
it "keeps the same trace_propagation_headers linked to the transaction when queued multiple times" do
135+
client.push('queue' => 'default', 'class' => HappyWorker, 'args' => [])
136+
137+
# push without span transaction to simulate pushing on the server
138+
Sentry.get_current_scope.clear
139+
client.push(queue.first.item)
140+
141+
q = queue.to_a
142+
expect(q.size).to be(2)
143+
first_headers = q.first["trace_propagation_headers"]
144+
expect(first_headers["sentry-trace"]).to eq(transaction.to_sentry_trace)
145+
expect(first_headers["baggage"]).to eq(transaction.to_baggage)
146+
147+
second_headers = q.second["trace_propagation_headers"]
148+
expect(second_headers["sentry-trace"]).to eq(transaction.to_sentry_trace)
149+
expect(second_headers["baggage"]).to eq(transaction.to_baggage)
150+
end
132151
end
133152
end

0 commit comments

Comments
 (0)