xinningsu / thinkphp-sentry
Sentry integration for ThinkPHP, Sentry整合ThinkPHP。
v1.0.0
2025-08-15 12:22 UTC
Requires
- php: >=8.0
- sentry/sentry: ^3.0.0 || ^4.0.0
- topthink/framework: ^6.0.0 || ^8.0.0
Requires (Dev)
- phpunit/phpunit: >=5.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2025-08-15 12:54:01 UTC
README
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 上看到错误报告。