2016-01-14 18:37:52 +05:30
|
|
|
module Gitlab
|
|
|
|
module Metrics
|
|
|
|
# Sidekiq middleware for tracking jobs.
|
|
|
|
#
|
|
|
|
# This middleware is intended to be used as a server-side middleware.
|
|
|
|
class SidekiqMiddleware
|
|
|
|
def call(worker, message, queue)
|
|
|
|
trans = Transaction.new("#{worker.class.name}#perform")
|
|
|
|
|
|
|
|
begin
|
2016-08-24 12:49:21 +05:30
|
|
|
# Old gitlad-shell messages don't provide enqueued_at/created_at attributes
|
|
|
|
trans.set(:sidekiq_queue_duration, Time.now.to_f - (message['enqueued_at'] || message['created_at'] || 0))
|
2016-01-14 18:37:52 +05:30
|
|
|
trans.run { yield }
|
2016-09-13 17:45:13 +05:30
|
|
|
rescue Exception => error # rubocop: disable Lint/RescueException
|
|
|
|
trans.add_event(:sidekiq_exception)
|
|
|
|
|
|
|
|
raise error
|
2016-01-14 18:37:52 +05:30
|
|
|
ensure
|
|
|
|
trans.finish
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|