diff --git a/app/code/Magento/NewRelicReporting/Model/Config.php b/app/code/Magento/NewRelicReporting/Model/Config.php
index 32e1078c01c9d..bcc87ec72d53f 100644
--- a/app/code/Magento/NewRelicReporting/Model/Config.php
+++ b/app/code/Magento/NewRelicReporting/Model/Config.php
@@ -161,6 +161,16 @@ public function getNewRelicAppName()
return (string)$this->scopeConfig->getValue('newrelicreporting/general/app_name');
}
+ /**
+ * Returns configured separate apps value
+ *
+ * @return bool
+ */
+ public function isSeparateApps()
+ {
+ return (bool)$this->scopeConfig->getValue('newrelicreporting/general/separate_apps');
+ }
+
/**
* Returns config setting for overall cron to be enabled
*
diff --git a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php
index 845ed0429d2c3..ec21e06976b8b 100644
--- a/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php
+++ b/app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php
@@ -41,6 +41,19 @@ public function reportError($exception)
}
}
+ /**
+ * Wrapper for 'newrelic_set_appname'
+ *
+ * @param string $appName
+ * @return void
+ */
+ public function setAppName(string $appName)
+ {
+ if (extension_loaded('newrelic')) {
+ newrelic_set_appname($appName);
+ }
+ }
+
/**
* Checks whether newrelic-php5 agent is installed
*
diff --git a/app/code/Magento/NewRelicReporting/Plugin/StatePlugin.php b/app/code/Magento/NewRelicReporting/Plugin/StatePlugin.php
new file mode 100644
index 0000000000000..0be7c72689e7f
--- /dev/null
+++ b/app/code/Magento/NewRelicReporting/Plugin/StatePlugin.php
@@ -0,0 +1,92 @@
+config = $config;
+ $this->newRelicWrapper = $newRelicWrapper;
+ $this->logger = $logger;
+ }
+
+ /**
+ * Set separate appname
+ *
+ * @param State $subject
+ * @param null $result
+ * @return void
+ *
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function afterSetAreaCode(State $state, $result)
+ {
+ if (!$this->shouldSetAppName()) {
+ return $result;
+ }
+
+ try {
+ $this->newRelicWrapper->setAppName($this->appName($state));
+ } catch (LocalizedException $e) {
+ $this->logger->critical($e);
+ return $result;
+ }
+ }
+
+ private function appName(State $state)
+ {
+ $code = $state->getAreaCode();
+ $current = $this->config->getNewRelicAppName();
+
+ return $current . ';' . $current . '_' . $code;
+ }
+
+ private function shouldSetAppName()
+ {
+ if (!$this->config->isNewRelicEnabled()) {
+ return false;
+ }
+
+ if (!$this->config->getNewRelicAppName()) {
+ return false;
+ }
+
+ if (!$this->config->isSeparateApps()) {
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml b/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml
index 582b7c752386a..98f9c55adbdf0 100644
--- a/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml
+++ b/app/code/Magento/NewRelicReporting/etc/adminhtml/system.xml
@@ -46,6 +46,11 @@
This is located by navigating to Settings from the New Relic APM website
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ In addition to the main app (which includes all PHP execution), separate apps for adminhtml and frontend will be created. Requires New Relic Application Name to be set.
+
diff --git a/app/code/Magento/NewRelicReporting/etc/di.xml b/app/code/Magento/NewRelicReporting/etc/di.xml
index 2dccc45c1129b..bab7d6611f14b 100644
--- a/app/code/Magento/NewRelicReporting/etc/di.xml
+++ b/app/code/Magento/NewRelicReporting/etc/di.xml
@@ -30,6 +30,9 @@
+
+
+
diff --git a/app/code/Magento/NewRelicReporting/i18n/en_US.csv b/app/code/Magento/NewRelicReporting/i18n/en_US.csv
index 433b1b22fcddd..5ea64d3d43439 100644
--- a/app/code/Magento/NewRelicReporting/i18n/en_US.csv
+++ b/app/code/Magento/NewRelicReporting/i18n/en_US.csv
@@ -21,3 +21,5 @@ General,General
"This is located by navigating to Settings from the New Relic APM website","This is located by navigating to Settings from the New Relic APM website"
Cron,Cron
"Enable Cron","Enable Cron"
+"Send Adminhtml and Frontend as Separate Apps","Send Adminhtml and Frontend as Separate Apps"
+"In addition to the main app (which includes all PHP execution), separate apps for adminhtml and frontend will be created. Requires New Relic Application Name to be set.","In addition to the main app (which includes all PHP execution), separate apps for adminhtml and frontend will be created. Requires New Relic Application Name to be set."
diff --git a/dev/tests/integration/testsuite/Magento/NewRelicReporting/Plugin/SeparateAppsTest.php b/dev/tests/integration/testsuite/Magento/NewRelicReporting/Plugin/SeparateAppsTest.php
new file mode 100644
index 0000000000000..92b0ec0f6a732
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/NewRelicReporting/Plugin/SeparateAppsTest.php
@@ -0,0 +1,47 @@
+objectManager = Bootstrap::getObjectManager();
+ }
+
+ /**
+ * @magentoConfigFixture default/newrelicreporting/general/enable 1
+ * @magentoConfigFixture default/newrelicreporting/general/app_name beverly_hills
+ * @magentoConfigFixture default/newrelicreporting/general/separate_apps 1
+ */
+ public function testAppNameIsSetWhenConfiguredCorrectly()
+ {
+ $newRelicWrapper = $this->getMockBuilder(NewRelicWrapper::class)
+ ->setMethods(['setAppName'])
+ ->getMock();
+
+ $this->objectManager->configure([NewRelicWrapper::class => ['shared' => true]]);
+ $this->objectManager->addSharedInstance($newRelicWrapper, NewRelicWrapper::class);
+
+ $newRelicWrapper->expects($this->once())
+ ->method('setAppName')
+ ->with($this->equalTo('beverly_hills;beverly_hills_90210'));
+
+ $state = $this->objectManager->get(State::class);
+
+ $state->setAreaCode('90210');
+ }
+}