vendor/sentry/sentry-symfony/src/EventListener/ConsoleListener.php line 32

Open in your IDE?
  1. <?php
  2. namespace Sentry\SentryBundle\EventListener;
  3. use Sentry\SentrySdk;
  4. use Sentry\State\HubInterface;
  5. use Sentry\State\Scope;
  6. use Symfony\Component\Console\Event\ConsoleCommandEvent;
  7. final class ConsoleListener
  8. {
  9.     /** @var HubInterface */
  10.     private $hub;
  11.     /**
  12.      * ConsoleListener constructor.
  13.      * @param HubInterface $hub
  14.      */
  15.     public function __construct(HubInterface $hub)
  16.     {
  17.         $this->hub $hub// not used, needed to trigger instantiation
  18.     }
  19.     /**
  20.      * This method ensures that the client and error handlers are registered at the start of the command
  21.      * execution cycle, and not only on exceptions
  22.      *
  23.      * @param ConsoleCommandEvent $event
  24.      *
  25.      * @return void
  26.      */
  27.     public function onConsoleCommand(ConsoleCommandEvent $event): void
  28.     {
  29.         $command $event->getCommand();
  30.         $commandName null;
  31.         if ($command) {
  32.             $commandName $command->getName();
  33.         }
  34.         SentrySdk::getCurrentHub()
  35.             ->configureScope(static function (Scope $scope) use ($commandName): void {
  36.                 $scope->setTag('command'$commandName ?? 'N/A');
  37.             });
  38.     }
  39. }