一、首先安装安装 sentry-laravel 扩展包
composer require sentry/sentry-laravel
二、如果使用的是 Laravel 5.5 或更高版本,则会自动发现该包。否则,您需要在 config/app.php 中手动配置它。
'providers' => array( // ... Sentry\Laravel\ServiceProvider::class, ), 'aliases' => array( // ... 'Sentry' => Sentry\Laravel\Facade::class, ),
三、将 Sentry 添加到 App/Exceptions/Handler.php。
public function report(Exception $exception) { if ($this->shouldReport($exception) && app()->bound('sentry')) { app('sentry')->captureException($exception); }
parent::report($exception);
}
四、终端运行 sentry:publish 命令
php artisan sentry:publish --dsn=https://19dd95ffda914562b4b86c9ddab7b5e5@o88936.ingest.sentry.io/193722
五、env文件配置sentry DSN
SENTRY_LARAVEL_DSN=you_dsn
Specify a fixed sample rate^M
SENTRY_TRACES_SAMPLE_RATE=1.0
Set a sampling rate for profiling - this is relative to traces_sample_rate^M
SENTRY_PROFILES_SAMPLE_RATE=1.0^M
六、执行artisan命令
php artisan sentry:test