Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#22047 Feature: Newrelic transaction name based on CLI name #22059

Merged
merged 5 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a public function is a backward incompatible change, however, this class is not public (not marked with @api tag)

{
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>