public function testGeneric() { $newRelic = new NewRelic('Ekino', 'XXX'); $this->assertEquals('Ekino', $newRelic->getName()); $this->assertEquals('XXX', $newRelic->getApiKey()); $this->assertEmpty($newRelic->getCustomMetrics()); $this->assertEmpty($newRelic->getCustomParameters()); $newRelic->addCustomMetric('foo', 'bar'); $newRelic->addCustomMetric('asd', 1); $expected = array('foo' => 0, 'asd' => 1); $this->assertEquals($expected, $newRelic->getCustomMetrics()); $newRelic->addCustomParameter('param1', 1); $expected = array('param1' => '1'); $this->assertEquals($expected, $newRelic->getCustomParameters()); }
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(); } }