public function testDefaults() { $newRelic = new NewRelic(null, null); $this->assertNotNull($newRelic->getName()); $this->assertEquals(ini_get('newrelic.appname'), $newRelic->getName()); $this->assertNotNull($newRelic->getLicenseKey()); $this->assertEquals(ini_get('newrelic.license'), $newRelic->getLicenseKey()); }
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()); }
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(); } }