From fb05432a8794deddc4e1d6a3bef2b5c778782555 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sun, 25 Jun 2023 15:32:45 +0100 Subject: [PATCH 1/2] 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. --- sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb | 2 ++ sentry-sidekiq/spec/sentry/sidekiq_spec.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb b/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb index 6658f2065..e99dc2b83 100644 --- a/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb +++ b/sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb @@ -25,6 +25,8 @@ def call(ex, context) contexts: { sidekiq: context_filter.filtered }, hint: { background: false } ) + ensure + scope&.clear end private diff --git a/sentry-sidekiq/spec/sentry/sidekiq_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq_spec.rb index 94730955b..5183e2339 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq_spec.rb @@ -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 @@ -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 From 3124a6c64f2aa70d4c3378e9dd1e35179b3b321e Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sun, 25 Jun 2023 15:39:22 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 403dcb4d4..36ebd1bb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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