Active Job
See our Active Job page for more information on how our Active Job instrumentation works.Action Cable
See our Action Cable page for more information on how our Action Cable instrumentation works.Configure AppSignal in an initializer
We recommend using ourconfig/appsignal.rb config file or environment variables to configure AppSignal.
By default, it’s not possible to configure AppSignal from a Rails initializer, because AppSignal loads before your application’s initializers, in order to be able to report errors that take place during initialization.
To configure AppSignal in a Rails initializer, first configure Rails to start AppSignal after the app’s initializers have run.
Appsignal.start in the initializers. The Ruby gem will start AppSignal automatically when Rails has run all initializers.
When a Rails app is configured to start AppSignal after the initializers have loaded, it is no longer possible to report errors from initializers when booting Rails app.
Error reporting from initializers
By default, AppSignal reports errors that occur in controller, Rake tasks and Active Job jobs. It does not report errors that occur when the application is booting, before the Rails initializers. To do get notified when these errors occur, adding the following to yourconfig.ru file, around the line that requires the environment.rb file.
Backtrace cleaner
With the Rails integration, AppSignal will run the backtrace of each exception through the Rails backtrace cleaner. This cleaner gives you the option to modify or filter out unwanted backtrace lines, removing clutter and noise from the backtrace. You can add or remove filters and silencers to the default configuration. Filters will mutate the given line. An example would be to remove theRails.root prefix.
Silencers will remove the line from the backtrace, if the given expression returns true. You can add these additional backtrace cleaner rules in an initialize.
For example:
Error reporter
AppSignal reports errors raised viaActiveSupport::ErrorReporter by default. ActiveSupport::ErrorReporter was introduced in Rails 7.0 to standardize custom error reporting.
You can disable this functionality with the enable_rails_error_reporter configuration option.
If a transaction is active in the context an error is reported through the Rails error reporter, it will include the same metadata and sample data as the active transaction: namespace, action name, tags, custom data, parameters, etc.
Namespace and action from the current transaction
When reporting errors, we determine the namespace and action name in which it takes place, such as a controller or background job, on a best-effort basis. The incident namespace and action name will not always be set or be accurate. If an AppSignal transaction is active (like in a web request or background job) the error reported withRails.error.handle/record will have the same namespace, action name, tags, parameters, custom data, etc. as the active transaction. If no AppSignal transaction is active, no namespace, action name, tags, etc. will be set by default.
Namespace and action from the context
If you want to change the reported error’s namespace and action name without changing them on the already active AppSignal transaction, you can customize this on the error reporter call.Tags from the active transaction
By default, the request/job’s transaction tags are copied to the error reporter’s error AppSignal transaction from the request/job’s transaction.Tags from context
You can add tags to a reported error by usingcontext in the Rails.error.handle/record call. These tags will only be set on the error reported with the Rails.error.handle/record methods.
Appsignal.add_tags.
Ruby gem 3 legacy behavior
In AppSignal for Ruby gem version 3 the error reporting behavior is different.- Errors reported with the
Rails.error.handlemethod are reported to AppSignal. - Errors reported with
Rails.error.recordare not reported to AppSignal to avoid reporting the error twice when it’s being reported by our Rails error reporting middleware.
Context inheritance limitations
In Ruby gem 3 the context inheritance from the active transaction is limited. The metadata and some of the sample data is only copied if it set at the timeRails.error.handle/record is called.
In practice this mean Rails controllers and Active Job jobs will be accurately reported. Other libraries like Sidekiq jobs, no action name is set when reporting errors with Rails.error.handle.
Tags set after Rails.error.handle/record is called are not reported for the error reported using this helper.
Runners
AppSignal will automatically report errors inside Rails runners. Some manual setup is also required to instrument a runner’s performance. We recommend putting the runner’s code in a separate file and wrap it in theAppsignal.monitor helper, as shown in the example below.
Bash
enable_at_exit_hook option is set to true (which should be the default on containers). This will ensure the data gets flushed to the AppSignal agent before the runner shuts down.