By default Laravel logs errors to storage/logs. Fine while building, but in production nobody looks there. With the Sentry SDK for Laravel and errors.nl you see every error right away, grouped and with its context. Here is how to set it up.
1. Create a project
Create a free account at errors.nl (or log in), create an organization and a project and copy the DSN. It looks like https://<key>@ingest.errors.nl/<project>.
2. Install the SDK
composer require sentry/sentry-laravel php artisan sentry:publish --dsn=https://<key>@ingest.errors.nl/<project>
The publish command creates config/sentry.php and puts the DSN in your .env as SENTRY_LARAVEL_DSN.
3. Hook up the exception handler
In Laravel 11 and newer you do that in bootstrap/app.php:
use Illuminate\Foundation\Configuration\Exceptions; use Sentry\Laravel\Integration; ->withExceptions(function (Exceptions $exceptions) { Integration::handles($exceptions); })
4. Test it
php artisan sentry:test
Within seconds a test error shows up under Issues in the dashboard.
5. Releases and environments
Pass the version with every deploy, so you see in which release an error started, and notice right away when a resolved error comes back:
[email protected] SENTRY_ENVIRONMENT=production
Turn error monitoring off for your local environment by leaving SENTRY_LARAVEL_DSN empty there.
6. Keep personal data out
In config/sentry.php, send_default_pii is false by default: the SDK then sends no IP addresses, cookies or user data. Leave it that way unless you really need them. On top of that, errors.nl filters passwords, tokens, e-mail addresses and account numbers from every error. Read more in Error monitoring and the GDPR.
Notifications
Want to know when something goes wrong without keeping the dashboard open? Turn on e-mail notifications for your project, or connect Slack, Teams, Discord or ntfy for push notifications on your phone.