class HeimdallApm::Instruments::SidekiqMiddleware

Public Instance Methods

call(_worker, item, queue, redis_pool = nil) { || ... } click to toggle source
# File lib/heimdall_apm/instruments/sidekiq.rb, line 4
def call(_worker, item, queue, redis_pool = nil)
  txn     = ::HeimdallApm::TransactionManager.current
  txn.annotate(latency: latency(item))
  txn.scope = unwrapped_worker_name(item)

  segment = ::HeimdallApm::Segment.new('Job'.freeze, 'all'.freeze)
  txn.start_segment(segment)

  yield
ensure
  txn.stop_segment
end

Private Instance Methods

latency(item) click to toggle source
# File lib/heimdall_apm/instruments/sidekiq.rb, line 23
def latency(item)
  created_at = item['enqueued_at'] || item['created_at']
  if created_at
    (Time.now.to_f - created_at)
  else
    0.0
  end
rescue
  0.0
end
unwrapped_worker_name(item) click to toggle source
# File lib/heimdall_apm/instruments/sidekiq.rb, line 19
def unwrapped_worker_name(item)
  item['wrapped'] || item['class']
end