arueckauer / mezzio-sentry-delegator
Mezzio Delegator 和 Sentry 错误监听器
1.5.0
2024-08-21 16:10 UTC
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- ext-curl: *
- laminas/laminas-servicemanager: ^3.22 || ^4.2
- laminas/laminas-stratigility: ^3.12 || ^4.0
- sentry/sdk: ^4.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.43
- laminas/laminas-coding-standard: ^2.5
- phpunit/phpunit: ^10.5
- rector/rector: ^1.2.3
- roave/security-advisories: dev-latest
- vimeo/psalm: ^5.25
README
Mezzio Delegator 和 Sentry 错误监听器
本软件包为 Sentry 提供初始化包装,并通过 Stratigility ErrorHandler
中间件的 ErrorListener
在 Sentry 中捕获可抛出对象(Throwable)的能力。Stratigility ErrorHandler
中间件 的文档。
安装
通过 Composer
composer require arueckauer/mezzio-sentry-delegator
配置
在项目的配置中提供 Sentry 的 dsn 以及可能的其它 配置选项,例如 config/autoload/services.local.php
。前往 PHP 配置文档 选择项目的 dsn。
<?php declare(strict_types = 1); use Sentry\Options as SentryOptions; return [ // [..] SentryOptions::class => [ 'dsn' => 'https://<key>@<account-id>.ingest.sentry.io/<project-id>', ], ];
初始化 Sentry
要初始化 Sentry,将以下行添加到 public/index.php
中的匿名函数。
(new MezzioSentryDelegator\SentryInitializer())($container);
通过连接委托器附加监听器
在项目的配置中声明委托器依赖项,例如 config/autoload/dependencies.global.php
。
<?php declare(strict_types = 1); use MezzioSentryDelegator\Delegator; use Laminas\Stratigility\Middleware\ErrorHandler; class ConfigProvider { public function __invoke() : array { return [ 'dependencies' => [ 'delegators' => [ ErrorHandler::class => [ Delegator::class, ], ], ], ]; } }