/**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof HttpExceptionInterface) {
         $this->interactor->noticeException($exception);
     }
 }
 protected function prepareInteractor()
 {
     if ($this->instrument) {
         $this->interactor->disableAutoRUM();
     }
     foreach ($this->newRelic->getCustomMetrics() as $name => $value) {
         $this->interactor->addCustomMetric($name, $value);
     }
     foreach ($this->newRelic->getCustomParameters() as $name => $value) {
         $this->interactor->addCustomParameter($name, $value);
     }
 }
 /**
  * On core response
  *
  * @param FilterResponseEvent $event
  */
 public function onCoreResponse(FilterResponseEvent $event)
 {
     if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isUsed()) {
         foreach ($this->newRelic->getCustomMetrics() as $name => $value) {
             $this->interactor->addCustomMetric($name, $value);
         }
         foreach ($this->newRelic->getCustomParameters() as $name => $value) {
             $this->interactor->addCustomParameter($name, $value);
         }
     }
     if ($this->instrument) {
         if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isUsed()) {
             $this->interactor->disableAutoRUM();
         }
         // Some requests might not want to get instrumented
         if ($event->getRequest()->attributes->get('_instrument', true)) {
             $response = $event->getResponse();
             // We can only instrument HTML responses
             if (substr($response->headers->get('Content-Type'), 0, 9) == 'text/html') {
                 $responseContent = $response->getContent();
                 if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isHeaderCalled()) {
                     $responseContent = preg_replace('/<\\s*head\\s*>/', '$0' . $this->interactor->getBrowserTimingHeader(), $responseContent);
                 }
                 if (null === $this->newRelicTwigExtension || false === $this->newRelicTwigExtension->isFooterCalled()) {
                     $responseContent = preg_replace('/<\\s*\\/\\s*body\\s*>/', $this->interactor->getBrowserTimingFooter() . '$0', $responseContent);
                 }
                 if ($responseContent) {
                     $response->setContent($responseContent);
                 }
             }
         }
     }
     if ($this->symfonyCache) {
         $this->interactor->endTransaction();
     }
 }
 public function testPreparingOfInteractor()
 {
     $headerValue = '__HEADER__TIMING__';
     $footerValue = '__FOOTER__TIMING__';
     $extension = new NewRelicExtension($this->newRelic, $this->interactor, true);
     $this->newRelic->expects($this->once())->method('getCustomMetrics')->will($this->returnValue(array('a' => 'b', 'c' => 'd')));
     $this->newRelic->expects($this->once())->method('getCustomParameters')->will($this->returnValue(array('e' => 'f', 'g' => 'h', 'i' => 'j')));
     $this->interactor->expects($this->once())->method('disableAutoRum');
     $this->interactor->expects($this->exactly(2))->method('addCustomMetric');
     $this->interactor->expects($this->exactly(3))->method('addCustomParameter');
     $this->interactor->expects($this->once())->method('getBrowserTimingHeader')->will($this->returnValue($headerValue));
     $this->interactor->expects($this->once())->method('getBrowserTimingFooter')->will($this->returnValue($footerValue));
     $this->assertEquals($headerValue, $extension->getNewrelicBrowserTimingHeader());
     $this->assertTrue($extension->isHeaderCalled());
     $this->assertFalse($extension->isFooterCalled());
     $this->assertEquals($footerValue, $extension->getNewrelicBrowserTimingFooter());
     $this->assertTrue($extension->isHeaderCalled());
     $this->assertTrue($extension->isFooterCalled());
 }
 /**
  * {@inheritdoc}
  */
 public function startTransaction($name)
 {
     $this->log(sprintf('Starting a new New Relic transaction for app "%s"', $name));
     $this->interactor->startTransaction($name);
 }
 /**
  * @param ConsoleExceptionEvent $event
  */
 public function onConsoleException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     $this->interactor->noticeException($exception);
 }