Skip to content

Commit

Permalink
ErrorHandler should cleanup the scope (#2059)
Browse files Browse the repository at this point in the history
* ErrorHandler should cleanup the scope

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.

* Update changelog
  • Loading branch information
st0012 authored Jun 26, 2023
1 parent 5054dbe commit 3131c7d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Fixes [#2054](https://github.com/getsentry/sentry-ruby/issues/2054)
- Ignore low-level Puma exceptions by default [#2055](https://github.com/getsentry/sentry-ruby/pull/2055)
- Use allowlist to filter `ActiveSupport` breadcrumbs' data [#2048](https://github.com/getsentry/sentry-ruby/pull/2048)
- ErrorHandler should cleanup the scope ([#2059](https://github.com/getsentry/sentry-ruby/pull/2059))


## 5.9.0
Expand Down
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 3131c7d

Please sign in to comment.