Laravel Lumen

Lumen is supported via a native package, sentry-laravel.

Sentry supports Lumen 5+.

Install

Install the sentry/sentry-laravel package:

Copied
composer require sentry/sentry-laravel

Register Sentry in bootstrap/app.php:

bootstrap/app.php
Copied
$app->register('Sentry\Laravel\ServiceProvider');

# Sentry must be registered before routes are included
require __DIR__ . '/../app/Http/routes.php';

To enable Sentry Performance Monitoring, the TracingServiceProvider has to be registered additionally in bootstrap/app.php:

bootstrap/app.php
Copied
$app->register('Sentry\Laravel\Tracing\ServiceProvider');

Add Sentry reporting to app/Exceptions/Handler.php:

app/Exceptions/Handler.php
Copied
public function report(Exception $exception)
{
    if (app()->bound('sentry') && $this->shouldReport($exception)) {
        app('sentry')->captureException($exception);
    }

    parent::report($exception);
}

Configure

Copy the Sentry configuration file from the vendor directory:

Copied
cp vendor/sentry/sentry-laravel/config/sentry.php config/sentry.php

Afterwards, add your DSN to .env:

.env
Copied
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0

Verify with Artisan

You can test your configuration using the provided artisan command:

Copied
php artisan sentry:test --transaction
[Sentry] DSN discovered!
[Sentry] Generating test Event
[Sentry] Sending test Event
[Sentry] Transaction sent: b22f130764c940c69d6860c212849d48
[Sentry] Event sent with ID: 4cde238791a9433c8876f4a545d9a95b

Verify with code

You can easily verify that Sentry is capturing errors in your Lumen application by creating a debug route that will throw an exception:

Copied
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.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").