Skip to content

Commit cd35fcf

Browse files
committed
Only set for spans present
1 parent f63653d commit cd35fcf

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

sentry-sidekiq/lib/sentry/sidekiq/sentry_context_middleware.rb

+7-9
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ def call(worker, job, queue)
2828
begin
2929
Sentry.with_child_span(op: "queue.process", description: "Process #{worker.class.name}") do |span|
3030
# Set span data
31-
span.set_data("messaging.message.id", job["jid"])
32-
span.set_data("messaging.destination.name", queue)
33-
span.set_data("messaging.message.body.size", job.to_json.size)
34-
span.set_data("messaging.message.receive.latency", ((Time.now.to_f - job["created_at"]) * 1000).to_i)
35-
span.set_data("messaging.message.retry.count", job["retry_count"] || 0)
31+
if span
32+
span.set_data("messaging.message.id", job["jid"])
33+
span.set_data("messaging.destination.name", queue)
34+
span.set_data("messaging.message.body.size", job.to_json.size)
35+
span.set_data("messaging.message.receive.latency", ((Time.now.to_f - job["created_at"]) * 1000).to_i)
36+
span.set_data("messaging.message.retry.count", job["retry_count"] || 0)
37+
end
3638

3739
yield
38-
rescue
39-
span.set_status("internal_error")
40-
raise
4140
end
4241
rescue => ex
43-
p ex
4442
finish_transaction(transaction, 500)
4543
raise
4644
end

sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
execute_worker(processor, HappyWorker, trace_propagation_headers: trace_propagation_headers)
7272

7373
expect(transport.events.count).to eq(1)
74+
7475
transaction = transport.events[0]
7576
expect(transaction).not_to be_nil
7677
expect(transaction.contexts.dig(:trace, :trace_id)).to eq(parent_transaction.trace_id)

sentry-sidekiq/spec/spec_helper.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,12 @@ def sidekiq_config(opts)
227227

228228
def execute_worker(processor, klass, **options)
229229
klass_options = klass.sidekiq_options_hash || {}
230-
231230
# for Ruby < 2.6
232231
klass_options.each do |k, v|
233232
options[k.to_sym] = v
234233
end
235234

236-
msg = Sidekiq.dump_json(jid: "123123", class: klass, args: [], **options)
235+
msg = Sidekiq.dump_json(created_at: Time.now.to_f, jid: "123123", class: klass, args: [], **options)
237236
work = Sidekiq::BasicFetch::UnitOfWork.new('queue:default', msg)
238237
process_work(processor, work)
239238
end

0 commit comments

Comments
 (0)