/** * @param ConsoleCommandEvent $event */ public function onConsoleCommand(ConsoleCommandEvent $event) { $command = $event->getCommand(); $input = $event->getInput(); if (in_array($command->getName(), $this->ignoredCommands)) { $this->interactor->ignoreTransaction(); } if ($this->newRelic->getName()) { $this->interactor->setApplicationName($this->newRelic->getName(), $this->newRelic->getLicenseKey(), $this->newRelic->getXmit()); } $this->interactor->setTransactionName($command->getName()); $this->interactor->enableBackgroundJob(); // send parameters to New Relic foreach ($input->getOptions() as $key => $value) { $key = '--' . $key; if (is_array($value)) { foreach ($value as $k => $v) { $this->interactor->addCustomParameter($key . '[' . $k . ']', $v); } } else { $this->interactor->addCustomParameter($key, $value); } } foreach ($input->getArguments() as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $this->interactor->addCustomParameter($key . '[' . $k . ']', $v); } } else { $this->interactor->addCustomParameter($key, $value); } } }
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(); } }
/** * {@inheritdoc} */ public function addCustomParameter($name, $value) { $this->log(sprintf('Adding custom New Relic parameter %s: %s', $name, $value)); $this->interactor->addCustomParameter($name, $value); }