Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should controllers use notify_airbrake over Airbrake.notify

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?

like image 403
Jacob Murphy Avatar asked Sep 27 '22 07:09

Jacob Murphy


2 Answers

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.

like image 86
kyrylo Avatar answered Sep 30 '22 07:09

kyrylo


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.

like image 36
San Avatar answered Sep 30 '22 06:09

San