/** * @return string * * @throws \RuntimeException */ public function getNewrelicBrowserTimingHeader() { if ($this->isHeaderCalled()) { throw new \RuntimeException('Function "ekino_newrelic_browser_timing_header" has already been called'); } $this->prepareInteractor(); $this->headerCalled = true; return $this->interactor->getBrowserTimingHeader(); }
/** * 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(); } }
/** * {@inheritdoc} */ public function getBrowserTimingHeader() { $this->log('Getting New Relic RUM timing header'); return $this->interactor->getBrowserTimingHeader(); }