debian-mirror-gitlab/lib/gitlab/sidekiq_middleware/instrumentation_logger.rb

27 lines
972 B
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
module Gitlab
module SidekiqMiddleware
class InstrumentationLogger
def call(worker, job, queue)
2021-03-11 19:13:27 +05:30
::Gitlab::InstrumentationHelper.init_instrumentation_data
2019-10-12 21:52:04 +05:30
yield
2021-03-11 19:13:27 +05:30
ensure
2019-10-12 21:52:04 +05:30
# The Sidekiq logger is called outside the middleware block, so
# we need to modify the job hash to pass along this information
# since RequestStore is only active in the Sidekiq middleware.
#
# Modifying the job hash in a middleware is permitted by Sidekiq
# because Sidekiq keeps a pristine copy of the original hash
# before sending it to the middleware:
# https://github.com/mperham/sidekiq/blob/53bd529a0c3f901879925b8390353129c465b1f2/lib/sidekiq/processor.rb#L115-L118
2021-04-29 21:17:54 +05:30
job[:instrumentation] = {}.tap do |instrumentation_values|
::Gitlab::InstrumentationHelper.add_instrumentation_data(instrumentation_values)
end
2019-10-12 21:52:04 +05:30
end
end
end
end