notamedia / yii2-sentry

Sentry logger for Yii2
MIT License
125 stars 50 forks source link

Yii not reporting user informations #57

Open koffisani opened 3 years ago

koffisani commented 3 years ago

I just configured this plugin as follows :

'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning','info'],
                ],
                [
                    'class' => 'notamedia\sentry\SentryTarget',
                    'dsn' => 'http://<id>@<server-address>/4',
                    'levels' => ['error', 'warning'],
                    // Write the context information (the default is true):
                    'context' => true,
                    // Additional options for `Sentry\init`:
                    //'clientOptions' => ['release' => 'my-project-name@2.3.12']
                    'on beforeAction' => function (\yii\base\ActionEvent $event) {
                        Yii::error("Test");
                        /** @var \yii\web\User $user */
                        $user = Yii::$app->has('user', true) ? Yii::$app->get('user', false) : null;
                        if ($user && ($identity = $user->getIdentity(true))) {
                            \Sentry\configureScope(function (\Sentry\State\Scope $scope) use ($identity) {
                                $scope->setUser([
                                    // User ID and IP will be added by logger automatically
                                    'username' => $identity->username,
                                    'email' => $identity->email,
                                ]);
                            });
                        }

                        return $event->isValid;
                    },
                ],
            ],
        ],

But unfortunately, only user's ID and IP are reported. Is there anything I've done wrong ? Thanks.

CookiesEater commented 2 years ago

Hi!

Sorry, but for now behavior of this feature is broken in sentry-php, please track this issue: https://github.com/getsentry/sentry-php/issues/1175