-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add Ability To Separate Frontend / Adminhtml in New Relic #12935
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
Changes from 4 commits
95b2c36
48066b2
7ceace8
0b68496
e186221
dc48306
bef36de
8141f17
24d7d4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\NewRelicReporting\Plugin; | ||
|
||
use Magento\Framework\App\State; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\NewRelicReporting\Model\Config; | ||
use Magento\NewRelicReporting\Model\NewRelicWrapper; | ||
|
||
class StatePlugin | ||
{ | ||
/** | ||
* @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 separate appname | ||
* | ||
* @param State $subject | ||
* @param null $result | ||
* @return void | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterSetAreaCode(State $state, $result) | ||
{ | ||
if (!$this->shouldSetAppName()) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we should have |
||
} | ||
|
||
try { | ||
$this->newRelicWrapper->setAppName($this->appName($state)); | ||
} catch (LocalizedException $e) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
private function appName(State $state) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better to rename it to "setAppName" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a getter. Would you prefer |
||
{ | ||
$code = $state->getAreaCode(); | ||
$current = $this->config->getNewRelicAppName(); | ||
|
||
return $current . ';' . $current . '_' . $code; | ||
} | ||
|
||
private function shouldSetAppName() | ||
{ | ||
if (!$this->config->isNewRelicEnabled()) { | ||
return false; | ||
} | ||
|
||
if (!$this->config->getNewRelicAppName()) { | ||
return false; | ||
} | ||
|
||
if (!$this->config->isSeparateApps()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to define variable type to "string" there, we're not supporting php 5.6 anymore