Skip to content

Commit

Permalink
Merge pull request #637 from drewish/sidekiq-cleanup
Browse files Browse the repository at this point in the history
Clear stale breadcrumbs and context after Sidekiq jobs
  • Loading branch information
nateberkopec committed Mar 3, 2017
2 parents c5a89c2 + 8004387 commit 1aa9f1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lib/raven/integrations/sidekiq.rb
Expand Up @@ -2,7 +2,16 @@
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)
Expand All @@ -13,9 +22,6 @@ def call(ex, context)
:extra => { :sidekiq => context },
:culprit => culprit_from_context(context)
)
ensure
Context.clear!
BreadcrumbBuffer.clear!
end

private
Expand Down Expand Up @@ -59,6 +65,9 @@ def culprit_from_context(context)

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
2 changes: 1 addition & 1 deletion spec/raven/integrations/sidekiq_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'raven/integrations/sidekiq'

describe Raven::Sidekiq do
describe Raven::SidekiqErrorHandler do
before(:all) do
Raven.configure do |config|
config.dsn = 'dummy://12345:67890@sentry.localdomain:3000/sentry/42'
Expand Down

0 comments on commit 1aa9f1f

Please sign in to comment.