使用 sentry 调试应用和监控异常

1 注册sentry账号

https://sentry.io/

2 创建项目,并按照提示设置项目

Install the sentry/sentry-laravel package:

$ composer require sentry/sentry-laravel:1.1.0

If you’re on Laravel 5.5 or later the package will be auto-discovered. Otherwise you will need to manually configure it in your config/app.php.

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

public function report(Exception $exception)
{
    if (app()->bound('sentry') && $this->shouldReport($exception)){
        app('sentry')->captureException($exception);
    }

    parent::report($exception);
}

Create the Sentry configuration file (config/sentry.php) with this command:

$ php artisan vendor:publish --provider="Sentry\Laravel\ServiceProvider"

Add your DSN to .env:

SENTRY_LARAVEL_DSN=https://xxxxxxxx@sentry.io/xxxxxx

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

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.

3 这样所有在系统中发生的异常可以在 sentry中查看了.

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!