hellowearemito / yii2-sentry

Sentry extension for Yii 2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I add the usercontext (ie user -id and user email )

robov opened this issue · comments

commented

How can I add the usercontext (ie user -id and user email ) to the sentry call ?

As a quick workaround I am simply overriding init() function in my own Component and use it instead

<?php

namespace common\components;

use mito\sentry\Component;

class SentryComponent extends Component
{
    public function init()
    {
        parent::init();

        if (!\Yii::$app->user->isGuest) {
            $user = \yii::$app->user->identity;

            $this->client->user_context(
                [
                    'id' => (string)$user->_id,
                    'username' => $user->username,
                    'email' => $user->email,
                    'ip_address' => $user->ip
                ]
            );
        }
    }
}
commented

Maybe a very wierd or stupid question, but it seems that I get this following error, where this code used to work. What am I missing here?

Call to a member function user_context() on array
$sentry = Yii::$app->get('sentry'); $sentry->client->user_context([

If the component is disabled, client is not initialized, it remains a configuration array.

commented

AWESOME !!!
thank you... !