Skip to content

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

@benjamindulau

Description

@benjamindulau

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions