1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2015 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
namespace Magento \NewRelicReporting \Model ;
7
7
8
+ use Magento \Framework \App \State ;
9
+ use Magento \Framework \App \ObjectManager ;
8
10
use Throwable ;
9
11
10
12
/**
@@ -17,6 +19,26 @@ class NewRelicWrapper
17
19
private const NEWRELIC_APPNAME = 'newrelic.appname ' ;
18
20
private const NEWRELIC_AUTO_INSTRUMENT = 'newrelic.browser_monitoring.auto_instrument ' ;
19
21
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
+
20
42
/**
21
43
* Wrapper for 'newrelic_add_custom_parameter' function
22
44
*
@@ -80,7 +102,8 @@ public function setTransactionName(string $transactionName): void
80
102
public function startBackgroundTransaction ()
81
103
{
82
104
if ($ this ->isExtensionInstalled ()) {
83
- newrelic_start_transaction (ini_get (self ::NEWRELIC_APPNAME ));
105
+ $ name = $ this ->getCurrentAppName ();
106
+ newrelic_start_transaction ($ name );
84
107
newrelic_background_job ();
85
108
}
86
109
}
@@ -161,4 +184,21 @@ public function getBrowserTimingFooter(bool $includeTags = true): ?string
161
184
162
185
return newrelic_get_browser_timing_footer ($ includeTags );
163
186
}
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
+ }
164
204
}
0 commit comments