yiisoft / yii-sentry
Yii框架的Sentry集成
2.0.1
2024-07-15 17:44 UTC
Requires
- php: ^8.0
- psr/http-message: ^1.0|^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- sentry/sdk: ^3.2
- sentry/sentry: ^3.11
- symfony/console: ^5.4|^6.0
- yiisoft/di: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.3
- httpsoft/http-message: ^1.0.9
- maglnet/composer-require-checker: ^4.2
- php-http/guzzle7-adapter: ^1.0
- phpunit/phpunit: ^9.5
- rector/rector: ^0.14.3
- roave/infection-static-analysis-plugin: ^1.16
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.30|^5.6
- yiisoft/error-handler: ^2.1
- yiisoft/yii-console: ^1.0
- yiisoft/yii-event: ^1.0
Suggests
- yiisoft/yii-console: Add error catching to console application
- yiisoft/yii-event: Add error catching to console application
This package is auto-updated.
Last update: 2024-09-15 18:09:25 UTC
README
Yii Sentry
要求
- PHP 8.0或更高版本。
安装
可以使用Composer安装此包。
此包需要PSR兼容的HTTP客户端和工厂,因此需要额外要求它
composer install httpsoft/http-message composer install php-http/guzzle7-adapter composer install yiisoft/yii-sentry
前两个可以被替换为你选择的其它包。
为了处理控制台错误,需要额外安装yii-console
和yii-event
包
composer install yiisoft/yii-console composer install yiisoft/yii-event
配置HTTP工厂和客户端(通常为config/common/di/sentry.php
)
use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\ClientInterface; use Http\Adapter\Guzzle7\Client as GuzzleClientAdapter; use Http\Client\HttpAsyncClient; use HttpSoft\Message\RequestFactory; use HttpSoft\Message\ResponseFactory; use HttpSoft\Message\StreamFactory; use HttpSoft\Message\UriFactory; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Yiisoft\Definitions\Reference; return [ // HTTP Factories StreamFactoryInterface::class => StreamFactory::class, RequestFactoryInterface::class => RequestFactory::class, LoggerInterface::class => NullLogger::class, UriFactoryInterface::class => UriFactory::class, ResponseFactoryInterface::class => ResponseFactory::class, // HTTP Client HttpClient::class => GuzzleClient::class, HttpAsyncClient::class => [ 'class' => GuzzleClientAdapter::class, '__construct()' => [ Reference::to(ClientInterface::class), ], ], ];
然后,将SentryMiddleware
添加到主应用程序中间件集合中,并在config/params.php
中配置DSN。默认情况下,控制台错误会被捕获,无需进行任何配置。
return [ // ... 'middlewares' => [ ErrorCatcher::class, SentryMiddleware::class, // <-- here SessionMiddleware::class, CookieMiddleware::class, CookieLoginMiddleware::class, LocaleMiddleware::class, Router::class, ], // ... 'yiisoft/yii-sentry' => [ 'handleConsoleErrors' => false, // Add to disable console errors. 'options' => [ // Set to `null` to disable error sending (note that in case of web application errors it only prevents // sending them via HTTP). To disable interactions with Sentry SDK completely, remove middleware and the // rest of the config. 'dsn' => $_ENV['SENTRY_DSN'] ?? null, 'environment' => $_ENV['YII_ENV'] ?? null, // Add to separate "production" / "staging" environment errors. ], ], // ... ]
注意,致命错误也会被处理。
在options
中,也可以传递额外的Sentry配置。有关键和值的详细信息,请参阅官方Sentry文档。
文档
如果您需要帮助或有任何问题,Yii论坛是一个不错的选择。您还可以查看其他Yii社区资源。
许可
Yii Sentry是免费软件。它根据BSD许可条款发布。有关更多信息,请参阅LICENSE
。
由Yii Software维护。