lib/elastic_apm/spies/sidekiq.rb in elastic-apm-3.2.0 vs lib/elastic_apm/spies/sidekiq.rb in elastic-apm-3.3.0
- old
+ new
@@ -8,27 +8,25 @@
ACTIVE_JOB_WRAPPER =
'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper'
# @api private
class Middleware
- # rubocop:disable Metrics/MethodLength
def call(_worker, job, queue)
name = SidekiqSpy.name_for(job)
transaction = ElasticAPM.start_transaction(name, 'Sidekiq')
ElasticAPM.set_label(:queue, queue)
yield
- transaction.done :success if transaction
+ transaction&.done :success
rescue ::Exception => e
ElasticAPM.report(e, handled: false)
- transaction.done :error if transaction
+ transaction&.done :error
raise
ensure
ElasticAPM.end_transaction
end
- # rubocop:enable Metrics/MethodLength
end
def self.name_for(job)
klass = job['class']
@@ -46,11 +44,10 @@
chain.add Middleware
end
end
end
- # rubocop:disable Metrics/MethodLength
def install_processor
require 'sidekiq/processor'
Sidekiq::Processor.class_eval do
alias start_without_apm start
@@ -74,10 +71,9 @@
ElasticAPM.stop
end
end
end
- # rubocop:enable Metrics/MethodLength
def install
install_processor
install_middleware
end