Sentry integration for ThinkPHP, Sentry整合ThinkPHP。
composer require xinningsu/thinkphp-sentry
-
拷贝这个 配置文件 到
config/sentry.php
, 请务必替换你的 dsn。return [ 'dsn' => 'your_sentry_dsn', // ...
其他配置项根据自己的需要修改。 更多配置项请参考: https://docs.sentry.io/platforms/php/configuration/options/
-
打开
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 上看到错误报告。