yiisoft / yii-sentry
A Sentry integration for Yii Framework
Fund package maintenance!
Open Collective
yiisoft
Installs: 12 111
Dependents: 4
Suggesters: 0
Security: 0
Stars: 15
Watchers: 19
Forks: 7
Open Issues: 2
Requires
- php: ^8.0
- psr/http-message: ^1.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: 2023-12-01 00:12:34 UTC
README
Yii Sentry
The package provides Sentry integration for Yii Framework
Installation
The package needs PSR-compatible HTTP client and factories so require it additionally to this package:
composer install httpsoft/http-message composer install php-http/guzzle7-adapter composer install yiisoft/yii-sentry
The first two can be replaced to other packages of your choice.
For handling console errors yii-console
and yii-event
packages are required additionally:
composer install yiisoft/yii-console composer install yiisoft/yii-event
Configure HTTP factories and client (usually that is config/common/sentry.php
):
<?php declare(strict_types=1); use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle7\Client as GuzzleClientAdapter; use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; 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(HttpClient::class), ], ], ];
Then add SentryMiddleware
to main application middleware set and configure DSN in config/params.php
. Console errors
are captured by default, there is no need to configure anything.
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. ], ], // ... ]
Note that fatal errors are handled too.
In options
you can also pass additional Sentry configuration. See
official Sentry docs for keys and values.
Unit testing
The package is tested with PHPUnit. To run tests:
./vendor/bin/phpunit
Mutation testing
The package tests are checked with Infection mutation framework. To run it:
./vendor/bin/infection
Static analysis
The code is statically analyzed with Psalm. To run static analysis:
./vendor/bin/psalm