Skip to content

Commit 3131c7d

Browse files
authored
ErrorHandler should cleanup the scope (#2059)
* 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
1 parent 5054dbe commit 3131c7d

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Fixes [#2054](https://github.com/getsentry/sentry-ruby/issues/2054)
1515
- Ignore low-level Puma exceptions by default [#2055](https://github.com/getsentry/sentry-ruby/pull/2055)
1616
- Use allowlist to filter `ActiveSupport` breadcrumbs' data [#2048](https://github.com/getsentry/sentry-ruby/pull/2048)
17+
- ErrorHandler should cleanup the scope ([#2059](https://github.com/getsentry/sentry-ruby/pull/2059))
1718

1819

1920
## 5.9.0

sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def call(ex, context)
2525
contexts: { sidekiq: context_filter.filtered },
2626
hint: { background: false }
2727
)
28+
ensure
29+
scope&.clear
2830
end
2931

3032
private

sentry-sidekiq/spec/sentry/sidekiq_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
expect(event["tags"]).to eq("queue" => "default", "jid" => "123123", "mood" => "sad")
7676
expect(event["transaction"]).to eq("Sidekiq/SadWorker")
7777
expect(event["breadcrumbs"]["values"][0]["message"]).to eq("I'm sad!")
78+
expect(Sentry.get_current_scope.tags).to be_empty
7879
end
7980

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

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

0 commit comments

Comments
 (0)