-
Notifications
You must be signed in to change notification settings - Fork 0
Using Airbrake with plain Ruby
END OF SUPPORT WARNING: On November 24, 2016 Airbrake v4 won't be supported anymore and this wiki will be deleted. Read more & discuss: https://github.com/airbrake/airbrake/issues/596
DEPRECATION WARNING: The information presented on this page is related to Airbrake v4 only. If you seek for information for Airbrake v5, please refer to our README!
You can also pass a hash to Airbrake.notify_or_ignore
method and store whatever you want,
not just an exception. And you can also use it anywhere, not just in
controllers:
Airbrake.configure do |config|
config.api_key = '1234deadbeef...'
end
begin
params = {
# params that you pass to a method that can throw an exception
}
my_unpredicable_method(params)
rescue => e
Airbrake.notify_or_ignore(
e,
parameters: params,
cgi_data: ENV.to_hash
)
end
While in your controllers you use the notify_airbrake
method, anywhere else in
your code, use Airbrake.notify_or_ignore
. Airbrake will get all the information
about the error itself. As for a hash, these are the keys you should pass:
-
:error_class
- Use this to group similar errors together. When Airbrake catches an exception it sends the class name of that exception object. -
:error_message
- This is the title of the error you see in the errors list. For exceptions it is"#{exception.class.name}: #{exception.message}"
-
:parameters
- While there are several ways to send additional data to Airbrake, passing a Hash as:parameters
as in the example above is the most common use case. When Airbrake catches an exception in a controller, the actual HTTP client request parameters are sent using this key.
Airbrake merges the hash you pass with these default options:
{
api_key: Airbrake.api_key,
error_message: 'Notification',
backtrace: caller,
parameters: {},
session: {}
}
You can override any of those parameters.
One common request we see is to send shell environment variables along with
manual exception notification. We recommend sending them along with CGI data (:cgi_data
).
See Airbrake::Notice#initialize
in lib/airbrake/notice.rb
for
more details.