diff --git a/.env-dist b/.env-dist index 33bd18c..647b78a 100644 --- a/.env-dist +++ b/.env-dist @@ -9,6 +9,7 @@ JWT_USER_SECRET= ## Внешние сервисы RECAPTCHA_PUBLIC= RECAPTCHA_SECRET= +SENTRY_DSN= ## SMTP параметры SMTP_USER= diff --git a/api/config/config.php b/api/config/config.php index 4e7ab1a..68e83c2 100644 --- a/api/config/config.php +++ b/api/config/config.php @@ -21,6 +21,17 @@ return [ 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ + [ + 'class' => mito\sentry\Target::class, + 'levels' => ['error', 'warning'], + 'except' => [ + 'legacy-authserver', + 'session', + 'yii\web\HttpException:*', + 'api\modules\session\exceptions\SessionServerException:*', + 'api\modules\authserver\exceptions\AuthserverException:*', + ], + ], [ 'class' => yii\log\FileTarget::class, 'levels' => ['error', 'warning'], diff --git a/autocompletion.php b/autocompletion.php index 1d99674..f91608c 100644 --- a/autocompletion.php +++ b/autocompletion.php @@ -21,6 +21,7 @@ class Yii extends \yii\BaseYii { * @property \common\components\RabbitMQ\Component $amqp * @property \GuzzleHttp\Client $guzzle * @property \common\components\EmailRenderer $emailRenderer + * @property \mito\sentry\Component $sentry */ abstract class BaseApplication extends yii\base\Application { } diff --git a/common/components/Sentry/Component.php b/common/components/Sentry/Component.php new file mode 100644 index 0000000..ce0b1c5 --- /dev/null +++ b/common/components/Sentry/Component.php @@ -0,0 +1,18 @@ +client) && !isset($this->client['release'])) { + $this->client['release'] = Yii::$app->version; + } + + parent::init(); + } + +} diff --git a/common/config/config.php b/common/config/config.php index ed68090..2819864 100644 --- a/common/config/config.php +++ b/common/config/config.php @@ -1,5 +1,6 @@ '1.1.3-dev', 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'components' => [ 'cache' => [ @@ -34,6 +35,15 @@ return [ ], ], ], + 'sentry' => [ + 'class' => common\components\Sentry\Component::class, + 'enabled' => !empty(getenv('SENTRY_DSN')), + 'dsn' => getenv('SENTRY_DSN'), + 'environment' => YII_ENV_DEV ? 'development' : 'production', + 'client' => [ + 'curl_method' => 'async', + ], + ], 'security' => [ 'passwordHashStrategy' => 'password_hash', ], diff --git a/composer.json b/composer.json index d897196..09c7d33 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "emarref/jwt": "~1.0.3", "ely/amqp-controller": "dev-master#d7f8cdbc66c45e477c9c7d5d509bc0c1b11fd3ec", "ely/email-renderer": "dev-master#38a148cd5081147acc31125ddc49966b149f65cf", - "predis/predis": "^1.0" + "predis/predis": "^1.0", + "mito/yii2-sentry": "dev-fix_init#27f00805cb906f73b2c6f8181c1c655decb9be70" }, "require-dev": { "yiisoft/yii2-codeception": "*", @@ -57,6 +58,10 @@ { "type": "git", "url": "git@gitlab.ely.by:elyby/oauth2-server.git" + }, + { + "type": "git", + "url": "git@github.com:erickskrauch/yii2-sentry.git" } ], "scripts": { diff --git a/console/config/config.php b/console/config/config.php index f7c04cf..748acc4 100644 --- a/console/config/config.php +++ b/console/config/config.php @@ -13,6 +13,10 @@ return [ 'components' => [ 'log' => [ 'targets' => [ + [ + 'class' => mito\sentry\Target::class, + 'levels' => ['error', 'warning'], + ], [ 'class' => yii\log\FileTarget::class, 'levels' => ['error', 'warning'], diff --git a/tests/codeception/config/config.php b/tests/codeception/config/config.php index dedd16f..edd34d4 100644 --- a/tests/codeception/config/config.php +++ b/tests/codeception/config/config.php @@ -20,5 +20,8 @@ return [ 'amqp' => [ 'class' => tests\codeception\common\_support\amqp\TestComponent::class, ], + 'sentry' => [ + 'enabled' => false, + ], ], ];