Skip to content

Commit

Permalink
ErrorHandler should cleanup the scope
Browse files Browse the repository at this point in the history
Because ErrorHandler is called outside of context middlewares,
we don't clean the scope when an exception occurs. This makes sure
ErrorHandler can have the context data set by middlewares. However, this
also means that those states would be left uncleaned after the exception is captured.

This commit makes sure that the scope is cleaned up after the exception is captured.
  • Loading branch information
st0012 committed Jun 25, 2023
1 parent 5054dbe commit fb05432
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def call(ex, context)
contexts: { sidekiq: context_filter.filtered },
hint: { background: false }
)
ensure
scope&.clear
end

private
Expand Down
2 changes: 2 additions & 0 deletions sentry-sidekiq/spec/sentry/sidekiq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
expect(event["tags"]).to eq("queue" => "default", "jid" => "123123", "mood" => "sad")
expect(event["transaction"]).to eq("Sidekiq/SadWorker")
expect(event["breadcrumbs"]["values"][0]["message"]).to eq("I'm sad!")
expect(Sentry.get_current_scope.tags).to be_empty
end

it "cleans up context from failed jobs" do
Expand All @@ -86,6 +87,7 @@

expect(event["tags"]).to eq("queue" => "default", "jid" => "123123", "mood" => "very sad")
expect(event["breadcrumbs"]["values"][0]["message"]).to eq("I'm very sad!")
expect(Sentry.get_current_scope.tags).to be_empty
end
end

Expand Down

0 comments on commit fb05432

Please sign in to comment.