Class: Appsignal::Hooks::AtExit::AtExitCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/hooks/at_exit.rb

Overview

Stop AppSignal before the app exists.

This is the default behavior and can be customized with the ‘enable_at_exit_hook` option.

When the ‘enable_at_exit_reporter` option is set to `true` (the default), it will report any unhandled errors that will crash the Ruby process.

If this error was previously reported by any of our instrumentation, the error will not also be reported here. This way we don’t report an error from a Rake task or instrumented script twice.

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.callObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/appsignal/hooks/at_exit.rb', line 30

def self.call
  report_error = false
  return unless Appsignal.config&.[](:enable_at_exit_reporter)

  error = $! # rubocop:disable Style/SpecialGlobalVars
  return unless error
  return if ignored_error?(error)
  return if Appsignal::Transaction.last_errors.include?(error)

  report_error = true

  Appsignal.report_error(error) do |transaction|
    transaction.set_namespace("unhandled")
  end
ensure
  at_exit_hook = Appsignal.config&.[](:enable_at_exit_hook)
  if at_exit_hook == "always" || (at_exit_hook == "on_error" && report_error)
    Appsignal.stop("at_exit")
  end
end

.ignored_error?(error) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/appsignal/hooks/at_exit.rb', line 57

def self.ignored_error?(error)
  IGNORED_ERRORS.include?(error.class)
end