11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2015 Adobe
4+ * All Rights Reserved .
55 */
66namespace Magento \NewRelicReporting \Model ;
77
8+ use Magento \Framework \App \State ;
9+ use Magento \Framework \App \ObjectManager ;
810use Throwable ;
911
1012/**
@@ -17,6 +19,26 @@ class NewRelicWrapper
1719 private const NEWRELIC_APPNAME = 'newrelic.appname ' ;
1820 private const NEWRELIC_AUTO_INSTRUMENT = 'newrelic.browser_monitoring.auto_instrument ' ;
1921
22+ /**
23+ * @var Config
24+ */
25+ private $ config ;
26+
27+ /**
28+ * @var State
29+ */
30+ private $ state ;
31+
32+ /**
33+ * @param ?Config $config
34+ * @param ?State $state
35+ */
36+ public function __construct (?Config $ config = null , ?State $ state = null )
37+ {
38+ $ this ->config = $ config ?? ObjectManager::getInstance ()->get (Config::class);
39+ $ this ->state = $ state ?? ObjectManager::getInstance ()->get (State::class);
40+ }
41+
2042 /**
2143 * Wrapper for 'newrelic_add_custom_parameter' function
2244 *
@@ -80,7 +102,8 @@ public function setTransactionName(string $transactionName): void
80102 public function startBackgroundTransaction ()
81103 {
82104 if ($ this ->isExtensionInstalled ()) {
83- newrelic_start_transaction (ini_get (self ::NEWRELIC_APPNAME ));
105+ $ name = $ this ->getCurrentAppName ();
106+ newrelic_start_transaction ($ name );
84107 newrelic_background_job ();
85108 }
86109 }
@@ -161,4 +184,21 @@ public function getBrowserTimingFooter(bool $includeTags = true): ?string
161184
162185 return newrelic_get_browser_timing_footer ($ includeTags );
163186 }
187+
188+ /**
189+ * Get current App name for NR transactions
190+ *
191+ * @return string
192+ */
193+ public function getCurrentAppName ()
194+ {
195+ if ($ this ->config ->isSeparateApps () &&
196+ $ this ->config ->getNewRelicAppName () &&
197+ $ this ->config ->isNewRelicEnabled ()) {
198+ $ code = $ this ->state ->getAreaCode ();
199+ $ current = $ this ->config ->getNewRelicAppName ();
200+ return $ current . '; ' . $ current . '_ ' . $ code ;
201+ }
202+ return ini_get (self ::NEWRELIC_APPNAME );
203+ }
164204}
0 commit comments