Д
Size: a a a
Д
y
A
A
y
y
ПА
y
AS
AS
O
МС
МС
ES
ES
СП
sentry/sdk
S
СП
'sentry/sentry' => [
'enable' => true,
'dsn' => 'https://xxxxxx',
],
<?php
declare(strict_types=1);
namespace common;
use Sentry\ClientBuilder;
use Sentry\ClientInterface;
use Sentry\Event;
use Sentry\EventHint;
use Sentry\SentrySdk;
use Yii;
use yii\base\BootstrapInterface;
use yii\web\HttpException;
final class SentryProvider implements BootstrapInterface
{
private $enable;
private $dsn;
public function __construct()
{
$this->dsn = Yii::$app->params['sentry/sentry']['dsn'];
$this->enable = (bool)Yii::$app->params['sentry/sentry']['enable'];
}
public function bootstrap($app): void
{
if (!$this->enable) {
return;
}
$config = [
'dsn' => $this->dsn,
'environment' => YII_ENV,
'traces_sample_rate' => YII_ENV_PROD === true ? 0.1 : 0,
'before_send' => static function (Event $event, EventHint $hint): ?Event {
if ($hint->exception instanceof HttpException) {
return null;
}
return $event;
},
];
$client = ClientBuilder::create($config)->getClient();
SentrySdk::init()->bindClient($client);
Yii::$container->set(ClientInterface::class, $client);
}
}
'bootstrap' => [
SentryProvider::class,
],