PHP & Laravel
Laravel
composer require sentry/sentry-laravel
php artisan sentry:publish --dsn=https://<public_key>@<your-errora-host>/<project_id>
sentry:publish writes config/sentry.php and appends the DSN to .env:
SENTRY_LARAVEL_DSN=https://<public_key>@<your-errora-host>/<project_id>
SENTRY_TRACES_SAMPLE_RATE=0.2
SENTRY_PROFILES_SAMPLE_RATE=1.0
SENTRY_ENVIRONMENT=production
SENTRY_RELEASE=myapp@1.4.2
Report exceptions
Laravel 11+ (bootstrap/app.php):
->withExceptions(function (Illuminate\Foundation\Configuration\Exceptions $exceptions) {
Sentry\Laravel\Integration::handles($exceptions);
})
Laravel 10 and earlier: call Integration::captureUnhandledException($e) from the
register() method of app/Exceptions/Handler.php.
Tracing
SENTRY_TRACES_SAMPLE_RATE alone instruments requests, queries, queue jobs, cache calls,
HTTP client calls and view rendering. Add the middleware for full request transactions:
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
$middleware->append(\Sentry\Laravel\Tracing\Middleware::class);
})
Logs
// config/logging.php
'channels' => [
'sentry' => [
'driver' => 'sentry',
'level' => env('LOG_LEVEL', 'info'),
'bubble' => true,
],
'stack' => ['driver' => 'stack', 'channels' => ['single', 'sentry']],
],
Then Log::warning('payment retried', ['order_id' => $order->id]); shows up in
Logs, context intact.
Scheduled commands (cron monitoring)
$schedule->command('invoices:generate')
->dailyAt('03:00')
->sentryMonitor('nightly-invoices');
The check-ins land against the monitor slug — see Cron monitoring.
User context
\Sentry\configureScope(function (\Sentry\State\Scope $scope) {
$scope->setUser(['id' => auth()->id(), 'username' => auth()->user()?->name]);
});
Plain PHP
composer require sentry/sdk
\Sentry\init([
'dsn' => getenv('SENTRY_DSN'),
'environment' => 'production',
'release' => 'myapp@1.4.2',
'traces_sample_rate' => 0.2,
'send_default_pii' => false,
]);
try {
riskyThing();
} catch (\Throwable $e) {
\Sentry\captureException($e);
}
Symfony
composer require sentry/sentry-symfony
# config/packages/sentry.yaml
sentry:
dsn: '%env(SENTRY_DSN)%'
options:
traces_sample_rate: 0.2
environment: '%kernel.environment%'
Verify
php artisan sentry:test
That command sends a test exception through the configured DSN and prints the result. Then check Issues.