Skip to content

Commit

Permalink
Do not report SystemExit errors in at_exit handler (#1257)
Browse files Browse the repository at this point in the history
The SystemExit can be a normal shutdown or a shutdown by the host. We do
not need to report those normal events.

If people do want to report this error they can add their own `at_exit`
handler, but let's not report it by default.
  • Loading branch information
tombruijn authored Aug 23, 2024
1 parent 9ea2d3e commit e9c0cad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: patch
type: fix
---

Do not report `SystemExit` errors from our `at_exit` error reporter.
10 changes: 10 additions & 0 deletions lib/appsignal/hooks/at_exit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ def install
class AtExitCallback
def self.call
error = $! # rubocop:disable Style/SpecialGlobalVars
return if ignored_error?(error)
return if Appsignal::Transaction.last_errors.include?(error)

Appsignal.report_error(error) do |transaction|
transaction.set_namespace("unhandled")
end
Appsignal.stop("at_exit")
end

IGNORED_ERRORS = [
# Normal exits from the application we do not need to report
SystemExit
].freeze

def self.ignored_error?(error)
IGNORED_ERRORS.include?(error.class)
end
end
end
end
Expand Down
13 changes: 12 additions & 1 deletion spec/lib/appsignal/hooks/at_exit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def call_callback
end
end

it "doesn't report the error if is also the last error reported" do
it "doesn't report the error if it is also the last error reported" do
with_error(ExampleException, "error message") do |error|
Appsignal.report_error(error)
expect(created_transactions.count).to eq(1)
Expand All @@ -69,4 +69,15 @@ def call_callback
end.to_not change { created_transactions.count }.from(1)
end
end

it "doesn't report the error if it is a SystemExit exception" do
with_error(SystemExit, "error message") do |error|
Appsignal.report_error(error)
expect(created_transactions.count).to eq(1)

expect do
call_callback
end.to_not change { created_transactions.count }.from(1)
end
end
end

0 comments on commit e9c0cad

Please sign in to comment.