dragon-code / sentriable-laravel
v2.1.0
2022-01-17 15:59 UTC
Requires
- php: ^7.2.5|^8.0
- illuminate/console: ^6.0|^7.0|^8.0|^9.0
- illuminate/contracts: ^6.0|^7.0|^8.0|^9.0
- illuminate/http: ^6.0|^7.0|^8.0|^9.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0
- illuminate/validation: ^6.0|^7.0|^8.0|^9.0
- sentry/sentry-laravel: ^2.10
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0
Suggests
- symfony/thanks: Give thanks (in the form of a GitHub) to your fellow PHP package maintainers
Conflicts
README
安装
要获取最新版本,只需使用 Composer 引入项目。
$ composer require dragon-code/sentriable-laravel
或者手动更新 composer.json
文件中的 require
块,然后运行 composer update
。
{ "require": { "dragon-code/sentriable-laravel": "^2.0" } }
从 andrey-helldar/sentriable-laravel
升级
- 在
composer.json
文件中将"andrey-helldar/sentriable-laravel": "^1.0"
替换为"dragon-code/sentriable-laravel": "^2.0"
; - 将
Helldar\Sentry
命名空间前缀替换为DragonCode\Sentry
; - 调用控制台命令
composer update
。
Lumen
此包主要针对 Laravel 开发,但也可以通过一些工作方式在 Lumen 中使用。因为 Lumen 的工作方式略有不同,它是 Laravel 的一个裸机版本,主要配置参数位于 bootstrap/app.php
中,因此需要进行一些修改。
您可以在 app/Providers/AppServiceProvider.php
中安装 Laravel Lang Publisher,并取消注释这一行以注册 App 服务提供者,以便正确加载。
// $app->register(App\Providers\AppServiceProvider::class);
如果您没有使用该行,通常需要在该行代码下添加以下代码到您的 bootstrap/app.php
文件的 注册服务提供者
部分。
$app->register(\DragonCode\Sentry\ServiceProvider::class);
如何使用
将 Sentry 报告添加到 App/Exceptions/Handler.php
。
Laravel 7.x 及以上版本
use DragonCode\Sentry\Traits\Sentriable; use Throwable; public function report(Throwable $exception) { parent::report($exception); if ($this->shouldReport($e)) { $this->sentryException($e); } }
Laravel 6.x
use DragonCode\Sentry\Traits\Sentriable; use Exception; public function report(Exception $exception) { parent::report($exception); if ($this->shouldReport($e)) { $this->sentryException($e); } }
有关配置 Sentry 包的更多信息,请参阅此处。
在其他地方使用代码
use DragonCode\Sentry\Traits\Sentriable use Throwable; protected function handle() { try { // some code } catch (Throwable $e) { $this->sentryException($e); } }
在循环中带有刷新使用
use DragonCode\Sentry\Traits\Sentriable; use Throwable; protected function handle() { foreach ($this->values as $item) { try { $this->sentryFlush(); // some code } catch (Throwable $e) { $this->sentryException($e); } } }
版本管理
要获取应用程序的当前版本,运行命令 php artisan git:version
。
如果当前提交设置了标签,它将传递到 Sentry 的 release
字段,否则将采用当前提交的 sha 值。
在部署应用程序时最好只执行一次。
您还需要取消注释 config/sentry.php
文件中的 release
键,并指定以下值
use DragonCode\Sentry\Facades\Sha; return [ // ... 'release' => Sha::get() // ... ];
许可证
本软件包遵循MIT许可协议。