https://github.com/xinningsu/thinkphp-sentry
Sentry integration for ThinkPHP, Sentry整合ThinkPHP。
https://github.com/xinningsu/thinkphp-sentry
error-handling error-reporting error-traces error-tracking sentry sentry-php thinkphp
Last synced: 7 months ago
JSON representation
Sentry integration for ThinkPHP, Sentry整合ThinkPHP。
- Host: GitHub
- URL: https://github.com/xinningsu/thinkphp-sentry
- Owner: xinningsu
- License: mit
- Created: 2025-08-15T12:24:13.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-08-15T12:52:46.000Z (7 months ago)
- Last Synced: 2025-08-15T20:19:50.904Z (7 months ago)
- Topics: error-handling, error-reporting, error-traces, error-tracking, sentry, sentry-php, thinkphp
- Language: PHP
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Sentry integration for ThinkPHP
Sentry integration for ThinkPHP, Sentry整合ThinkPHP。
[](./LICENSE)
[](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/build-status/master)
[](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/?branch=master)
[](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry)
[](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry)
# 安装
```
composer require xinningsu/thinkphp-sentry
```
# 配置
1. 拷贝这个 [配置文件](./config/sentry.php) 到 `config/sentry.php`, 请务必替换你的 dsn。
```php
return [
'dsn' => 'your_sentry_dsn',
// ...
```
其他配置项根据自己的需要修改。
更多配置项请参考: https://docs.sentry.io/platforms/php/configuration/options/
2. 打开 `app/ExceptionHandle.php`,在 `report` 方法里新增一行代码
```php
class ExceptionHandle extends Handle
{
// ...
public function report(Throwable $exception): void
{
// 使用内置的方式记录异常日志
parent::report($exception);
// 在 report 方法里新增下面这行代码
\Sentry\captureException($exception);
}
}
```
# 测试
可以在 `controller` 中加入下面代码
```php
\Sentry\Sentry::log('error', new \Exception('test exception'));
```
或直接在 `controller` 中接抛出异常
```php
throw new \Exception('test exception');
```
然后看是否能在 Sentry 上看到错误报告。
# License
[MIT](./LICENSE)