Add BugSnag to your legacy Laravel applications.
This integration supports Laravel 4 (and Laravel 5 running PHP 5.4 or lower). For newer applications, see the updated Laravel integration guide.
Add bugsnag/bugsnag-laravel
to your composer.json
as follows:
$ composer require "bugsnag/bugsnag-laravel:^1.7"
Register our service provider in providers
array in config/app.php
:
'providers' => [
...
'Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider',
],
Register the BugSnag
alias in the aliases
array in config/app.php
:
'aliases' => [
...
'Bugsnag' => 'Bugsnag\BugsnagLaravel\BugsnagFacade',
],
Create a config/bugsnag.php
configuration file as follows:
$ php artisan config:publish bugsnag/bugsnag-laravel
To associate your application with a project in your BugSnag dashboard, you’ll need to set your Integration API Key in app/config/packages/bugsnag/bugsnag-laravel/config.php
:
return array(
'api_key' => 'YOUR_API_KEY_HERE'
);
You can find this key immediately after creating a new project from your BugSnag dashboard, or later on your project’s settings page.
If you’d like to configure BugSnag further, check out the configuration options reference.
At this point, BugSnag should be installed and configured, and any unhandled exceptions will be automatically detected and should appear in your BugSnag dashboard.
You can ensure that all unhandled exceptions are sent to BugSnag by using our ExceptionHandler
.
Remove the following line from app/Exceptions/Handler.php
:
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
And replace it with the BugSnag ExceptionHandler
:
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
Reporting handled exceptions can be accomplished as follows:
try {
// Some potentially crashy code
} catch (Exception $e) {
Bugsnag::notifyException($e);
}
When reporting handled exceptions, it’s often helpful to send us custom diagnostic data or to adjust the severity of particular errors. For more information, see reporting handled errors.
BugSnag will automatically capture the following data for every exception:
It is often helpful to send us additional application-specific diagnostic data. This can be accomplished as follows:
Bugsnag::setBeforeNotifyFunction(function ($error) {
$error->setMetaData([
'account' => [
'name' => 'Acme Co.',
'paying_customer' => true,
]
]);
});
For more information, see the customizing error reports reference.
In order to correlate errors with customer reports, or to see a list of users who experienced each error, it is helpful to capture and display user information on your BugSnag dashboard.
If you are Laravel’s built-in authentication, we will attempt to automatically capture information about the currently authenticated user and send this to your BugSnag dashboard.
If you are using a different authentication system, you can set this information as follows by putting the following in the boot
method of a service provider:
Bugsnag::setBeforeNotifyFunction(function ($error) {
$error->setUser([
'id' => '123456',
'name' => 'Leeroy Jenkins',
'email' => 'leeeeroy@jenkins.com',
]);
});
For more information, see configuration options.
By sending your source revision or application version to us when you deploy a new version of your app, you’ll be able to see which deploy each error was introduced in, or seen in.
See our Build API guide for more details.
bugsnag-laravel
and bugsnag-php
, the open-source libraries powering BugSnag for Laravel, on GitHub