Skip to content

Commit

Permalink
fixup! wip - define latency calc methods based on sidekiq ver
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Feb 28, 2025
1 parent f46798b commit 0138b2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ def set_span_data(span, id:, queue:, latency: nil, retry_count: nil)

if ::Gem::Version.new(::Sidekiq::VERSION) >= ::Gem::Version.new("8.0.0.beta")
def calculate_latency(job)
(Time.now.to_f * 1000).to_i - job["enqueued_at"] if job["enqueued_at"]
now_in_ms - job["enqueued_at"] if job["enqueued_at"]
end
else
def calculate_latency(job)
((Time.now.to_f - job["enqueued_at"]) * 1000).to_i if job["enqueued_at"]
end
end

def now_in_ms
::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond)
end
end

class SentryContextServerMiddleware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@
expect(transaction.spans.count).to eq(0)
expect(transaction.contexts[:trace][:data]['messaging.message.id']).to eq('123456') # Explicitly set above.
expect(transaction.contexts[:trace][:data]['messaging.destination.name']).to eq('default')
expect(transaction.contexts[:trace][:data]['messaging.message.receive.latency']).to eq(86400000)
expect(transaction.contexts[:trace][:data]['messaging.message.retry.count']).to eq(0)

if WITH_SIDEKIQ_8
expect(transaction.contexts[:trace][:data]['messaging.message.receive.latency']).to eq(0)
else
expect(transaction.contexts[:trace][:data]['messaging.message.receive.latency']).to eq(86400000)
end
end

if MIN_SIDEKIQ_6
Expand Down
6 changes: 5 additions & 1 deletion sentry-sidekiq/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ def sidekiq_config(opts)
WITH_SIDEKIQ_7 ? ::Sidekiq::Config.new(opts) : SidekiqConfigMock.new(opts)
end

def now_in_ms
::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond)
end

def execute_worker(processor, klass, **options)
klass_options = klass.sidekiq_options_hash || {}
# for Ruby < 2.6
Expand All @@ -260,7 +264,7 @@ def execute_worker(processor, klass, **options)
timecop_delay = options.delete(:timecop_delay)

if WITH_SIDEKIQ_8
current_time_ms = (Time.now.to_f * 1000).to_i
current_time_ms = now_in_ms
msg = Sidekiq.dump_json(created_at: current_time_ms, enqueued_at: current_time_ms, jid: jid, class: klass, args: [], **options)
else
msg = Sidekiq.dump_json(created_at: Time.now.to_f, enqueued_at: Time.now.to_f, jid: jid, class: klass, args: [], **options)
Expand Down

0 comments on commit 0138b2d

Please sign in to comment.