appsignal

Exceptional Error Reporting for Rails Exceptions

Connor James
Tom de Bruijn

Connor James and Tom de Bruijn on

Exceptional Error Reporting for Rails Exceptions

If you want insights into your application's exceptions but don't have time to invest in adding verbose logic to your code, we've got some exceptional news: The AppSignal for Ruby gem 3.4.1 now supports the Rails error reporter!

With this change, you can simplify your AppSignal integration, streamline your code and begin reporting errors on the fly without raising an error page and interrupting your user's flow.

In this blog post, we'll show you how you can start reporting errors to AppSignal with the Rails Error Reporter.

Bye, Bye Begin Blocks

The Rails Error Reporter removes the need for verbose begin blocks in your code and provides a more explicit and standardized way of reporting your application's exceptions.

Previously, when you wanted to report an exception to AppSignal without raising an error (also known as swallowing an error), you'd use a begin block:

Ruby
begin raise "Oh CRUD!" rescue => error Appsignal.send_error(error) do |transaction| # Here, you manually define the action and namespace where the exception has occurred transaction.set_action("StroopwaffleController#request_waffles") transaction.set_namespace("web") end end

With the Rails Error Reporter, we can now simplify this down to as few as three lines of code, and AppSignal will automatically detect the action and namespace from the parent web request or background job:

Ruby
Rails.error.handle do raise "CRUD!" end

Errors raised using the Rails Error Reporter's handle method will be reported to AppSignal as separate samples, allowing for multiple errors to be reported within the same request or job. If you use the record method, the error will not be swallowed and will instead be re-raised. In these instances, our Rails middleware will report the error.

Contextual Error Reporting

If you want to use a custom namespace or action name for a request or job's transaction, you can use our set_namespace and set_action helper methods:

Ruby
Appsignal.set_namespace("custom_namespace") Appsignal.set_action("CustomizedActionName#index")

Alternatively, if you want to use a custom namespace and action name only when reporting a specific error, you can add them to the Rails Error Reporters context:

Ruby
Rails.error.handle(:context => { :appsignal => { :namespace => "custom_namespace", :action => "CustomizedActionName#index" } }) do raise "Contextual CRUD!" end

You can also supply custom tags to the error's context, which you will be able to use to filter through your application's incidents:

Ruby
Rails.error.handle(:context => { :tag1 => "value1", :tag2 => "value2" }) do raise "Tagged CRUD!" end
Raised error with custom tags

Exceptional Monitoring for Exceptional Applications

You can read more about AppSignal's error reporting in our Rails documentation, and if you experience any issues when using Rails Error Reporter, get in touch with our exceptional support team.

AppSignal's Error Reporting is just one of our many developer-driven features that help you get the most out of monitoring your application. Developers also enjoy using our monitoring because we have:

  • An intuitive interface that is easy to navigate.
  • Simple and predictable pricing.
  • Developer-to-developer support.

Don't forget, if you're new to AppSignal, we'll welcome you onboard with an exceptionally delicious shipment of stroopwafels 🍪 😋

Connor James

Connor James

Official technical writer at AppSignal. Podcast addict who loves cannoli so much that he's considering changing his name to Connoli. He thinks there's a `u` in color. You might find him on the mic, on the stage, or lying on the sofa when he's off Documentation Duty.

All articles by Connor James
Tom de Bruijn

Tom de Bruijn

Tom is a developer at AppSignal, organizer, and writer from Amsterdam, The Netherlands.

All articles by Tom de Bruijn

Become our next author!

Find out more

AppSignal monitors your apps

AppSignal provides insights for Ruby, Rails, Elixir, Phoenix, Node.js, Express and many other frameworks and libraries. We are located in beautiful Amsterdam. We love stroopwafels. If you do too, let us know. We might send you some!

Discover AppSignal
AppSignal monitors your apps