使用 sentry 除錯應用和監控異常

pplboy發表於2019-08-02

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中檢視了.

使用 sentry 除錯應用和監控異常

相關文章