lib/raven/integrations/sidekiq.rb in sentry-raven-2.3.1 vs lib/raven/integrations/sidekiq.rb in sentry-raven-2.4.0
- old
+ new
@@ -1,23 +1,29 @@
require 'time'
require 'sidekiq'
module Raven
- class Sidekiq
+ class SidekiqCleanupMiddleware
+ def call(_worker, _job, _queue)
+ yield
+ ensure
+ Context.clear!
+ BreadcrumbBuffer.clear!
+ end
+ end
+
+ class SidekiqErrorHandler
ACTIVEJOB_RESERVED_PREFIX = "_aj_".freeze
def call(ex, context)
context = filter_context(context)
Raven.capture_exception(
ex,
:message => ex.message,
:extra => { :sidekiq => context },
:culprit => culprit_from_context(context)
)
- ensure
- Context.clear!
- BreadcrumbBuffer.clear!
end
private
# Once an ActiveJob is queued, ActiveRecord references get serialized into
@@ -57,8 +63,11 @@
end
end
if Sidekiq::VERSION > '3'
Sidekiq.configure_server do |config|
- config.error_handlers << Raven::Sidekiq.new
+ config.error_handlers << Raven::SidekiqErrorHandler.new
+ config.server_middleware do |chain|
+ chain.add Raven::SidekiqCleanupMiddleware
+ end
end
end