Laravel 7.x 接入 Sentry 日志监控服务步骤

Sentry 是一套错误日志收集系统,支持许多常用语言的接入,也支持多种常见框架的接入,包括但是不限于 Laravel, Symfony 等等,下图显示了部分支持接入的程序语言或框架:

Laravel 7.x 框架接入 Sentry 的步骤,参考官方的文档:https://docs.sentry.io/platforms/php/guides/laravel/

第一步、安装 sentry-laravel 扩展包

composer require sentry/sentry-laravel

第二步、在 Laravel 异常处理类里增加报告 sentry 代码:

public function report(Throwable $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

执行成功后,会自动将 sentry_dsn 信息写入到环境配置 .env 文件里。

第四步、终端运行 sentry:test 命令

$ php artisan sentry:test
[Sentry] DSN discovered!
[Sentry] Generating test Event
[Sentry] Sending test Event
[Sentry] Event sent with ID: d76caf6903bf4990a8842077b304e54e

再登录 sentry 后台查看 issues 问题列表:

接入成功了!

posted @ 2020-11-25 11:14  imzhi  阅读(683)  评论(0)    收藏  举报