xinningsu / thinkphp-sentry
Sentry integration for ThinkPHP, Sentry整合ThinkPHP。
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/xinningsu/thinkphp-sentry
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-10-15 13:14:44 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 上看到错误报告。