Skip to content

Commit 4d8c702

Browse files
mpchadwickihor-sviziev
authored andcommitted
Add mechanics for separate appnames
1 parent 0d169ac commit 4d8c702

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\NewRelicReporting\Plugin;
7+
8+
use Magento\Framework\App\State;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\NewRelicReporting\Model\Config;
11+
use Magento\NewRelicReporting\Model\NewRelicWrapper;
12+
13+
class StatePlugin
14+
{
15+
/**
16+
* @var Config
17+
*/
18+
private $config;
19+
20+
/**
21+
* @var NewRelicWrapper
22+
*/
23+
private $newRelicWrapper;
24+
25+
/**
26+
* @param Config $config
27+
* @param NewRelicWrapper $newRelicWrapper
28+
*/
29+
public function __construct(
30+
Config $config,
31+
NewRelicWrapper $newRelicWrapper
32+
) {
33+
$this->config = $config;
34+
$this->newRelicWrapper = $newRelicWrapper;
35+
}
36+
37+
/**
38+
* Set separate appname
39+
*
40+
* @param State $subject
41+
* @param null $result
42+
* @return void
43+
*
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
45+
*/
46+
public function afterSetAreaCode(State $state, $result)
47+
{
48+
if (!$this->shouldSetAppName()) {
49+
return;
50+
}
51+
52+
try {
53+
$this->newRelicWrapper->setAppName($this->appName($state));
54+
} catch (LocalizedException $e) {
55+
return;
56+
}
57+
}
58+
59+
private function appName(State $state)
60+
{
61+
$code = $state->getAreaCode();
62+
$current = $this->config->getNewRelicAppName();
63+
64+
return $current . ';' . $current . '_' . $code;
65+
}
66+
67+
private function shouldSetAppName()
68+
{
69+
if (!$this->config->isNewRelicEnabled()) {
70+
return false;
71+
}
72+
73+
if (!$this->config->getNewRelicAppName()) {
74+
return false;
75+
}
76+
77+
if (!$this->config->isSeparateApps()) {
78+
return false;
79+
}
80+
81+
return true;
82+
}
83+
}

app/code/Magento/NewRelicReporting/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<type name="Magento\Framework\App\Http">
3131
<plugin name="framework-http-newrelic" type="Magento\NewRelicReporting\Plugin\HttpPlugin"/>
3232
</type>
33+
<type name="Magento\Framework\App\State">
34+
<plugin name="framework-state-newrelic" type="Magento\NewRelicReporting\Plugin\StatePlugin"/>
35+
</type>
3336
<type name="Magento\Framework\Console\CommandListInterface">
3437
<arguments>
3538
<argument name="commands" xsi:type="array">

0 commit comments

Comments
 (0)