Skip to content

Commit 0138b2d

Browse files
committed
fixup! wip - define latency calc methods based on sidekiq ver
1 parent f46798b commit 0138b2d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ def set_span_data(span, id:, queue:, latency: nil, retry_count: nil)
1616

1717
if ::Gem::Version.new(::Sidekiq::VERSION) >= ::Gem::Version.new("8.0.0.beta")
1818
def calculate_latency(job)
19-
(Time.now.to_f * 1000).to_i - job["enqueued_at"] if job["enqueued_at"]
19+
now_in_ms - job["enqueued_at"] if job["enqueued_at"]
2020
end
2121
else
2222
def calculate_latency(job)
2323
((Time.now.to_f - job["enqueued_at"]) * 1000).to_i if job["enqueued_at"]
2424
end
2525
end
26+
27+
def now_in_ms
28+
::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond)
29+
end
2630
end
2731

2832
class SentryContextServerMiddleware

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@
9696
expect(transaction.spans.count).to eq(0)
9797
expect(transaction.contexts[:trace][:data]['messaging.message.id']).to eq('123456') # Explicitly set above.
9898
expect(transaction.contexts[:trace][:data]['messaging.destination.name']).to eq('default')
99-
expect(transaction.contexts[:trace][:data]['messaging.message.receive.latency']).to eq(86400000)
10099
expect(transaction.contexts[:trace][:data]['messaging.message.retry.count']).to eq(0)
100+
101+
if WITH_SIDEKIQ_8
102+
expect(transaction.contexts[:trace][:data]['messaging.message.receive.latency']).to eq(0)
103+
else
104+
expect(transaction.contexts[:trace][:data]['messaging.message.receive.latency']).to eq(86400000)
105+
end
101106
end
102107

103108
if MIN_SIDEKIQ_6

sentry-sidekiq/spec/spec_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ def sidekiq_config(opts)
249249
WITH_SIDEKIQ_7 ? ::Sidekiq::Config.new(opts) : SidekiqConfigMock.new(opts)
250250
end
251251

252+
def now_in_ms
253+
::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond)
254+
end
255+
252256
def execute_worker(processor, klass, **options)
253257
klass_options = klass.sidekiq_options_hash || {}
254258
# for Ruby < 2.6
@@ -260,7 +264,7 @@ def execute_worker(processor, klass, **options)
260264
timecop_delay = options.delete(:timecop_delay)
261265

262266
if WITH_SIDEKIQ_8
263-
current_time_ms = (Time.now.to_f * 1000).to_i
267+
current_time_ms = now_in_ms
264268
msg = Sidekiq.dump_json(created_at: current_time_ms, enqueued_at: current_time_ms, jid: jid, class: klass, args: [], **options)
265269
else
266270
msg = Sidekiq.dump_json(created_at: Time.now.to_f, enqueued_at: Time.now.to_f, jid: jid, class: klass, args: [], **options)

0 commit comments

Comments
 (0)