vendor/sentry/sentry-symfony/src/EventListener/AbstractTracingRequestListener.php line 40

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\SentryBundle\EventListener;
  4. use Sentry\State\HubInterface;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. use Symfony\Component\Routing\Route;
  9. abstract class AbstractTracingRequestListener
  10. {
  11.     use KernelEventForwardCompatibilityTrait;
  12.     /**
  13.      * @var HubInterface The current hub
  14.      */
  15.     protected $hub;
  16.     /**
  17.      * Constructor.
  18.      *
  19.      * @param HubInterface $hub The current hub
  20.      */
  21.     public function __construct(HubInterface $hub)
  22.     {
  23.         $this->hub $hub;
  24.     }
  25.     /**
  26.      * This method is called once a response for the current HTTP request is
  27.      * created, but before it is sent off to the client. Its use is mainly for
  28.      * gathering information like the HTTP status code and attaching them as
  29.      * tags of the span/transaction.
  30.      *
  31.      * @param ResponseEvent $event The event
  32.      */
  33.     public function handleKernelResponseEvent(ResponseEvent $event): void
  34.     {
  35.         $response $event->getResponse();
  36.         $span $this->hub->getSpan();
  37.         if (null === $span) {
  38.             return;
  39.         }
  40.         $span->setHttpStatus($response->getStatusCode());
  41.     }
  42.     /**
  43.      * Gets the name of the route or fallback to the controller FQCN if the
  44.      * route is anonymous (e.g. a subrequest).
  45.      *
  46.      * @param Request $request The HTTP request
  47.      */
  48.     protected function getRouteName(Request $request): string
  49.     {
  50.         $route $request->attributes->get('_route');
  51.         if ($route instanceof Route) {
  52.             $route $route->getPath();
  53.         }
  54.         if (null === $route) {
  55.             $route $request->attributes->get('_controller');
  56.             if (\is_array($route) && \is_callable($routetrue)) {
  57.                 $route sprintf('%s::%s'\is_object($route[0]) ? get_debug_type($route[0]) : $route[0], $route[1]);
  58.             }
  59.         }
  60.         return \is_string($route) ? $route '<unknown>';
  61.     }
  62. }