An open API service indexing awesome lists of open source software.

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。

Awesome Lists containing this project

README

          

# Sentry integration for ThinkPHP
Sentry integration for ThinkPHP, Sentry整合ThinkPHP。

[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![Build Status](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/badges/build.png?b=master)](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/build-status/master)
[![Code Coverage](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/xinningsu/thinkphp-sentry/badges/code-intelligence.svg?b=master)](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)