Laravel 5.x
Laravel 5.x is supported until version 2.14.x of the sentry/sentry-laravel
package.
Laravel is supported using a native package: sentry-laravel.
This guide is for Laravel 5.x. We also provide instructions for the latest Laravel as well as Lumen-specific instructions.
Install the sentry/sentry-laravel
package:
composer require "sentry/sentry-laravel:^2.14"
If you're on Laravel 5.5 or higher, the package will be auto-discovered. Otherwise, you will need to manually configure it in your config/app.php
.
config/app.php
'providers' => array(
// ...
Sentry\Laravel\ServiceProvider::class,
),
'aliases' => array(
// ...
'Sentry' => Sentry\Laravel\Facade::class,
),
Add Sentry reporting to App/Exceptions/Handler.php
.
App/Exceptions/Handler.php
public function report(Exception $exception)
{
if ($this->shouldReport($exception) && app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
parent::report($exception);
}
Configure the Sentry DSN with this command:
php artisan sentry:publish --dsn=https://examplePublicKey@o0.ingest.sentry.io/0
It creates the config file (config/sentry.php
) and adds the DSN
to your .env
file.
.env
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
You can test your configuration using the provided sentry:test
artisan command:
php artisan sentry:test
You can verify that Sentry is capturing errors in your Laravel application by creating a route that will throw an exception:
routes/web.php
Route::get('/debug-sentry', function () {
throw new Exception('My first Sentry error!');
});
Visiting this route will trigger an exception that will be captured by Sentry.
When Sentry is installed in your application, it will also be active when you are developing or running tests.
You most likely don't want errors to be sent to Sentry when you are developing or running tests. To avoid this, set the DSN value to null
to disable sending errors to Sentry.
You can also do this by not defining SENTRY_LARAVEL_DSN
in your .env
or by defining it as SENTRY_LARAVEL_DSN=null
.
If you do leave Sentry enabled when developing or running tests, it's possible for it to have a negative effect on the performance of your application or test suite.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- composer:sentry/sentry-laravel
- Version:
- 4.5.1
- Repository:
- https://github.com/getsentry/sentry-laravel