Exceptional Error Reporting for Rails Exceptions
source link: https://blog.appsignal.com/2023/06/20/exceptional-error-reporting-for-rails-exceptions.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
appsignal
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:
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:
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:
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:
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:
Rails.error.handle(:context => { :tag1 => "value1", :tag2 => "value2" }) do
raise "Tagged CRUD!"
end
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 🍪 😋
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK