xinningsu/thinkphp-sentry

Sentry integration for ThinkPHP, Sentry整合ThinkPHP。

v1.0.0 2025-08-15 12:22 UTC

This package is auto-updated.

Last update: 2025-08-15 12:54:01 UTC


README

Sentry integration for ThinkPHP, Sentry整合ThinkPHP。

MIT licensed Build Status Code Coverage Scrutinizer Code Quality Code Intelligence Status

安装

composer require xinningsu/thinkphp-sentry

配置

  1. 拷贝这个 配置文件config/sentry.php, 请务必替换你的 dsn。

    return [
        'dsn' => 'your_sentry_dsn',
        // ...

    其他配置项根据自己的需要修改。 更多配置项请参考: https://docs.sentry.io/platforms/php/configuration/options/

  2. 打开 app/ExceptionHandle.php,在 report 方法里新增一行代码

    class ExceptionHandle extends Handle
    {
        // ...
        public function report(Throwable $exception): void
        {
            // 使用内置的方式记录异常日志
            parent::report($exception);
      
            // 在 report 方法里新增下面这行代码
            \Sentry\captureException($exception);
        }
    }

测试

可以在 controller 中加入下面代码

\Sentry\Sentry::log('error', new \Exception('test exception'));

或直接在 controller 中接抛出异常

throw new \Exception('test exception');

然后看是否能在 Sentry 上看到错误报告。

License

MIT