rollbar-php-symfony-bundle
rollbar-php-symfony-bundle copied to clipboard
Possibility to use service as person_fn rather than a static function
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.
any news ?
Guys help me, is there any way to access logged in user in person_fn
static function or is it just useless?