Skip to content

Commit

Permalink
#22047 Add Transaction name to NewRelic based on Command name
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Mar 30, 2019
1 parent a9a72b6 commit a1661a5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function reportError($exception)
*/
public function setAppName(string $appName)
{
if (extension_loaded('newrelic')) {
if ($this->isExtensionInstalled()) {
newrelic_set_appname($appName);
}
}
Expand All @@ -66,4 +66,17 @@ public function isExtensionInstalled()
}
return false;
}

/**
* Wrapper for 'newrelic_name_transaction'
*
* @param string $transactionName
* @return void
*/
public function setTransactionName(string $transactionName): void
{
if ($this->isExtensionInstalled()) {
newrelic_name_transaction($transactionName);
}
}
}
44 changes: 44 additions & 0 deletions app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\NewRelicReporting\Plugin;

use Magento\Framework\Exception\LocalizedException;
use Magento\NewRelicReporting\Model\Config;
use Magento\NewRelicReporting\Model\NewRelicWrapper;

class CommandPlugin
{
/**
* @var Config
*/
private $config;

/**
* @var NewRelicWrapper
*/
private $newRelicWrapper;

/**
* @param Config $config
* @param NewRelicWrapper $newRelicWrapper
*/
public function __construct(
Config $config,
NewRelicWrapper $newRelicWrapper
) {
$this->config = $config;
$this->newRelicWrapper = $newRelicWrapper;
}

public function beforeRun(\Symfony\Component\Console\Command\Command $command, ...$args)
{
$this->newRelicWrapper->setTransactionName(
sprintf('CLI %s', $command->getName())
);

return $args;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/NewRelicReporting/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@
</argument>
</arguments>
</type>
<type name="Symfony\Component\Console\Command\Command">
<plugin name="newrelic-describe-commands" type="Magento\NewRelicReporting\Plugin\CommandPlugin"/>
</type>
</config>

0 comments on commit a1661a5

Please sign in to comment.