public function onKernelRequest(GetResponseEvent $event): void
    {
        if (! $event->isMasterRequest()) {
            return;
        }

        $currentClient = Hub::getCurrent()->getClient();
        if (null === $currentClient || ! $currentClient->getOptions()->shouldSendDefaultPii()) {
            return;
        }

        $token = null;

        if ($this->tokenStorage instanceof TokenStorageInterface) {
            $token = $this->tokenStorage->getToken();
        }

        if (
            null !== $token
            && null !== $this->authorizationChecker
            && $token->isAuthenticated()
            && $this->authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
        ) {
            $userData = $this->getUserData($token->getUser());
        }

        $userData['ip_address'] = $event->getRequest()->getClientIp();

        Hub::getCurrent()
            ->configureScope(function (Scope $scope) use ($userData): void {
                $scope->setUser($userData);
            });
    }
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (! $event->isMasterRequest()) {
            return;
        }

        $currentClient = Hub::getCurrent()->getClient();
        if (null === $currentClient || ! $currentClient->getOptions()->shouldSendDefaultPii()) {
            return;
        }

        $token = null;

        if ($this->tokenStorage instanceof TokenStorageInterface) {
            $token = $this->tokenStorage->getToken();
        }

        if (
            null !== $token
            && null !== $this->authorizationChecker
            && $token->isAuthenticated()
            && $this->authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
        ) {
            $userData = $this->getUserData($token->getUser());
        }

        $userData['ip_address'] = $event->getRequest()->getClientIp();

        Hub::getCurrent()
            ->configureScope(function (Scope $scope) use ($userData): void {
                $scope->setUser($userData);
            });
    }
public function onKernelRequest ( GetResponseEvent $ event ) : void { if ( ! $ event -> isMasterRequest ( ) ) { return ; } $ currentClient = Hub :: getCurrent ( ) -> getClient ( ) ; if ( null === $ currentClient || ! $ currentClient -> getOptions ( ) -> shouldSendDefaultPii ( ) ) { return ; } $ token = null ; if ( $ this -> tokenStorage instanceof TokenStorageInterface ) { $ token = $ this -> tokenStorage -> getToken ( ) ; } if ( null !== $ token && null !== $ this -> authorizationChecker && $ token -> isAuthenticated ( ) && $ this -> authorizationChecker -> isGranted ( AuthenticatedVoter :: IS_AUTHENTICATED_REMEMBERED ) ) { $ userData = $ this -> getUserData ( $ token -> getUser ( ) ) ; } $ userData [ 'ip_address' ] = $ event -> getRequest ( ) -> getClientIp ( ) ; Hub :: getCurrent ( ) -> configureScope ( function ( Scope $ scope ) use ( $ userData ) : void { $ scope -> setUser ( $ userData ) ; } ) ; }
Set the username from the security context by listening on core.request

@param GetResponseEvent $event
Set the username from the security context by listening on core . request