In the Airbrake wiki, it says to use notify_airbrake
in controllers instead of Airbrake.notify
, but doesn't explain why. What is the benefit of using notify_airbrake
in controllers and why should it not be used elsewhere?
notify_airbrake
is just a helper method. You don't have to use it (feel free to use Airbrake.notify
). However notify_airbrake
attaches extra information to the notice (like current user, session, Rack environment, etc). With Airbrake.notify
you will only send what you pass to the method.
This is the beauty of open source. You can look at the code and figure out how and why something is implemented the way it is.
Having said that, look at airbrake code, specifically controller_methods.rb
file (https://github.com/airbrake/airbrake/blob/3033798f69d20706f13fc0e3d79572041e9c7205/lib/airbrake/rails/controller_methods.rb)
You can see that notify_airbrake
method actually calls a variant of Airbrake.notify
(Airbrake.notify_or_ignore
) after it extracts some extra information automatically like session data, request url, request params etc which are only available in the controller context. If they didn't do it this way, we will have to extract that information manually in the controller and pass it along. It's only there to make our lives easier :)
My 2 cents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With