andrey-helldar / sentriable-laravel
资助软件包维护!
TheDragonCode
Open Collective
Boosty
Yoomoney
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);
如果您不使用该行,通常在管理多个 Lumen 安装时很有用,您需要在 bootstrap/app.php
中的 Register Service Providers
部分添加此行代码。
$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 许可协议。