From a1661a5effb01e5fcd3cdf846d3052d8ec8e642f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Sat, 30 Mar 2019 13:47:29 +0100 Subject: [PATCH] #22047 Add Transaction name to NewRelic based on Command name --- .../Model/NewRelicWrapper.php | 15 ++++++- .../Plugin/CommandPlugin.php | 44 +++++++++++++++++++ app/code/Magento/NewRelicReporting/etc/di.xml | 3 ++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php diff --git a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php index 9882a1ce9b0b8..c37d3bcd2bba9 100644 --- a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php +++ b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php @@ -49,7 +49,7 @@ public function reportError($exception) */ public function setAppName(string $appName) { - if (extension_loaded('newrelic')) { + if ($this->isExtensionInstalled()) { newrelic_set_appname($appName); } } @@ -66,4 +66,17 @@ public function isExtensionInstalled() } return false; } + + /** + * Wrapper for 'newrelic_name_transaction' + * + * @param string $transactionName + * @return void + */ + public function setTransactionName(string $transactionName): void + { + if ($this->isExtensionInstalled()) { + newrelic_name_transaction($transactionName); + } + } } diff --git a/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php b/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php new file mode 100644 index 0000000000000..1d24ed609bef7 --- /dev/null +++ b/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php @@ -0,0 +1,44 @@ +config = $config; + $this->newRelicWrapper = $newRelicWrapper; + } + + public function beforeRun(\Symfony\Component\Console\Command\Command $command, ...$args) + { + $this->newRelicWrapper->setTransactionName( + sprintf('CLI %s', $command->getName()) + ); + + return $args; + } +} diff --git a/app/code/Magento/NewRelicReporting/etc/di.xml b/app/code/Magento/NewRelicReporting/etc/di.xml index bab7d6611f14b..15516f6df89be 100644 --- a/app/code/Magento/NewRelicReporting/etc/di.xml +++ b/app/code/Magento/NewRelicReporting/etc/di.xml @@ -40,4 +40,7 @@ + + +