Skip to content

Commit a1661a5

Browse files
committed
#22047 Add Transaction name to NewRelic based on Command name
1 parent a9a72b6 commit a1661a5

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function reportError($exception)
4949
*/
5050
public function setAppName(string $appName)
5151
{
52-
if (extension_loaded('newrelic')) {
52+
if ($this->isExtensionInstalled()) {
5353
newrelic_set_appname($appName);
5454
}
5555
}
@@ -66,4 +66,17 @@ public function isExtensionInstalled()
6666
}
6767
return false;
6868
}
69+
70+
/**
71+
* Wrapper for 'newrelic_name_transaction'
72+
*
73+
* @param string $transactionName
74+
* @return void
75+
*/
76+
public function setTransactionName(string $transactionName): void
77+
{
78+
if ($this->isExtensionInstalled()) {
79+
newrelic_name_transaction($transactionName);
80+
}
81+
}
6982
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\Exception\LocalizedException;
9+
use Magento\NewRelicReporting\Model\Config;
10+
use Magento\NewRelicReporting\Model\NewRelicWrapper;
11+
12+
class CommandPlugin
13+
{
14+
/**
15+
* @var Config
16+
*/
17+
private $config;
18+
19+
/**
20+
* @var NewRelicWrapper
21+
*/
22+
private $newRelicWrapper;
23+
24+
/**
25+
* @param Config $config
26+
* @param NewRelicWrapper $newRelicWrapper
27+
*/
28+
public function __construct(
29+
Config $config,
30+
NewRelicWrapper $newRelicWrapper
31+
) {
32+
$this->config = $config;
33+
$this->newRelicWrapper = $newRelicWrapper;
34+
}
35+
36+
public function beforeRun(\Symfony\Component\Console\Command\Command $command, ...$args)
37+
{
38+
$this->newRelicWrapper->setTransactionName(
39+
sprintf('CLI %s', $command->getName())
40+
);
41+
42+
return $args;
43+
}
44+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@
4040
</argument>
4141
</arguments>
4242
</type>
43+
<type name="Symfony\Component\Console\Command\Command">
44+
<plugin name="newrelic-describe-commands" type="Magento\NewRelicReporting\Plugin\CommandPlugin"/>
45+
</type>
4346
</config>

0 commit comments

Comments
 (0)