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 1/4] #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 @@ + + + From 07f8a65073331732f511c61fb66954365e2ada11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Sat, 30 Mar 2019 13:47:54 +0100 Subject: [PATCH 2/4] Remove unused `use` section --- app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php b/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php index 1d24ed609bef7..065455e2a27c3 100644 --- a/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php +++ b/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php @@ -5,7 +5,6 @@ */ namespace Magento\NewRelicReporting\Plugin; -use Magento\Framework\Exception\LocalizedException; use Magento\NewRelicReporting\Model\Config; use Magento\NewRelicReporting\Model\NewRelicWrapper; From 638b73a514788822c19d8506763f79c0ac5a70b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Sat, 30 Mar 2019 13:50:23 +0100 Subject: [PATCH 3/4] Cleanup for Wrapper --- .../Model/NewRelicWrapper.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php index c37d3bcd2bba9..bce42b4e90074 100644 --- a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php +++ b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php @@ -21,7 +21,7 @@ class NewRelicWrapper */ public function addCustomParameter($param, $value) { - if (extension_loaded('newrelic')) { + if ($this->isExtensionInstalled()) { newrelic_add_custom_parameter($param, $value); return true; } @@ -36,7 +36,7 @@ public function addCustomParameter($param, $value) */ public function reportError($exception) { - if (extension_loaded('newrelic')) { + if ($this->isExtensionInstalled()) { newrelic_notice_error($exception->getMessage(), $exception); } } @@ -55,28 +55,28 @@ public function setAppName(string $appName) } /** - * Checks whether newrelic-php5 agent is installed + * Wrapper for 'newrelic_name_transaction' * - * @return bool + * @param string $transactionName + * @return void */ - public function isExtensionInstalled() + public function setTransactionName(string $transactionName): void { - if (extension_loaded('newrelic')) { - return true; + if ($this->isExtensionInstalled()) { + newrelic_name_transaction($transactionName); } - return false; } /** - * Wrapper for 'newrelic_name_transaction' + * Checks whether newrelic-php5 agent is installed * - * @param string $transactionName - * @return void + * @return bool */ - public function setTransactionName(string $transactionName): void + public function isExtensionInstalled() { - if ($this->isExtensionInstalled()) { - newrelic_name_transaction($transactionName); + if (extension_loaded('newrelic')) { + return true; } + return false; } } From 9cd00fa8d80e085719d5a23491d9235e21da327f Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 16 Apr 2019 15:55:20 +0300 Subject: [PATCH 4/4] Fix static tests. --- .../NewRelicReporting/Plugin/CommandPlugin.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php b/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php index 065455e2a27c3..04ad3d0504d34 100644 --- a/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php +++ b/app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php @@ -3,11 +3,16 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\NewRelicReporting\Plugin; use Magento\NewRelicReporting\Model\Config; use Magento\NewRelicReporting\Model\NewRelicWrapper; +use Symfony\Component\Console\Command\Command; +/** + * Describe NewRelic commands plugin. + */ class CommandPlugin { /** @@ -32,7 +37,14 @@ public function __construct( $this->newRelicWrapper = $newRelicWrapper; } - public function beforeRun(\Symfony\Component\Console\Command\Command $command, ...$args) + /** + * Set NewRelic Transaction name before running command. + * + * @param Command $command + * @param array $args + * @return array + */ + public function beforeRun(Command $command, ...$args) { $this->newRelicWrapper->setTransactionName( sprintf('CLI %s', $command->getName())