Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to use service as person_fn rather than a static function #52

Open
benjamindulau opened this issue Jul 31, 2019 · 2 comments

Comments

@benjamindulau
Copy link

We can only use a static function for person_fn which is not really useful since most of the time we'd want to access some dependencies from inside the function and thus use a service instead of a static.

In older versions of Rollbar, we were able to add person data from inside a monolog.processor tagged service. Like that:

class RollbarContextProcessor
{
    /** @var TokenStorageInterface */
    protected $tokenStorageInterface;
    
    public function __construct(TokenStorageInterface $tokenStorageInterface)
    {
        $this->tokenStorageInterface = $tokenStorageInterface;
    }    

    public function processRecord(array $record): array
    {
        $record = $this->recordUser($record);
    }

    private function recordUser(array $record): array
    {
        if (!\is_object($this->tokenStorageInterface->getToken())) {
            return $record;
        }

        /** @var User $user */
        $user = $this->tokenStorageInterface->getToken()->getUser();

        if ($user instanceof User) {
            $record['context']['payload']['person'] = [
                'id'         => $user->getId(),
                'username'   => $user->getUsername(),
                'facebookId' => $user->getFacebookId(),
                'roles'      => implode('|', $user->getRoles())
            ];
        }

        return $record;
    }
}

But as of now, Rollbar doesn't consider this as being person data (like before) as it is added in body.extra variables.

@armetiz
Copy link

armetiz commented May 29, 2020

any news ?

@kwolniak
Copy link

kwolniak commented Mar 2, 2023

Guys help me, is there any way to access logged in user in person_fn static function or is it just useless?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants