Catching Laravel 5 exceptions with Sentry (and Raven)
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
The process for catching exceptions has changed a little, especially now as we actually have a place to do it - the report()
method of your app's exception handler. It even tells you in the method comment. This is a lot better than having to register it in a random place like global.php
or start.php
as you'll know where to find it.
In addition to the change in Laravel 5, an upstream change in Monolog affected the way we attach the user context to the exception. In the example below, we pass these exceptions off to Sentry in the production environment only (of course, change this as necessary) and attach the user context through Monolog, instead of the Raven client directly.
I had to use Laravel facades in this example as I was unable to inject the application or auth guard into the exception handler. If someone knows a better way, please let me know in the comments.