Skip to content

Commit

Permalink
ENGCOM-4634: #22047 Feature: Newrelic transaction name based on CLI n…
Browse files Browse the repository at this point in the history
…ame #22059
  • Loading branch information
sidolov authored Apr 25, 2019
2 parents 0ed0838 + 451114b commit a91194f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NewRelicWrapper
*/
public function addCustomParameter($param, $value)
{
if (extension_loaded('newrelic')) {
if ($this->isExtensionInstalled()) {
newrelic_add_custom_parameter($param, $value);
return true;
}
Expand All @@ -36,7 +36,7 @@ public function addCustomParameter($param, $value)
*/
public function reportError($exception)
{
if (extension_loaded('newrelic')) {
if ($this->isExtensionInstalled()) {
newrelic_notice_error($exception->getMessage(), $exception);
}
}
Expand All @@ -49,11 +49,24 @@ public function reportError($exception)
*/
public function setAppName(string $appName)
{
if (extension_loaded('newrelic')) {
if ($this->isExtensionInstalled()) {
newrelic_set_appname($appName);
}
}

/**
* Wrapper for 'newrelic_name_transaction'
*
* @param string $transactionName
* @return void
*/
public function setTransactionName(string $transactionName): void
{
if ($this->isExtensionInstalled()) {
newrelic_name_transaction($transactionName);
}
}

/**
* Checks whether newrelic-php5 agent is installed
*
Expand Down
55 changes: 55 additions & 0 deletions app/code/Magento/NewRelicReporting/Plugin/CommandPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\NewRelicReporting\Plugin;

use Magento\NewRelicReporting\Model\Config;
use Magento\NewRelicReporting\Model\NewRelicWrapper;
use Symfony\Component\Console\Command\Command;

/**
* Describe NewRelic commands plugin.
*/
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;
}

/**
* Set NewRelic Transaction name before running command.
*
* @param Command $command
* @param array $args
* @return array
*/
public function beforeRun(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 a91194f

Please sign in to comment.