Skip to content

Commit

Permalink
Merge forwardport of #11944 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11944.patch (created by @mpchadwick) based on commit(s):
  1. acc49c1
  2. debea42
  3. 2cc85a1
  4. 0137050
  5. 46a0c9d
  6. a9d408e
  7. a22b31b
  8. b9ee593
  9. 6bc4fcf
  • Loading branch information
magento-engcom-team authored Jan 23, 2018
2 parents ff33a1b + 8161593 commit df7ef2b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public function addCustomParameter($param, $value)
return false;
}

/**
* Wrapper for 'newrelic_notice_error' function
*
* @param Exception $exception
* @return void
*/
public function reportError($exception)
{
if (extension_loaded('newrelic')) {
newrelic_notice_error($exception->getMessage(), $exception);
}
}

/**
* Checks whether newrelic-php5 agent is installed
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\NewRelicReporting\Model\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\NewRelicReporting\Model\Config;
use Magento\NewRelicReporting\Model\NewRelicWrapper;

/**
* Class ReportApplicationHandledExceptionToNewRelic
*/
class ReportApplicationHandledExceptionToNewRelic implements ObserverInterface
{
/**
* @var Config
*/
protected $config;

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

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

public function execute(Observer $observer)
{
if ($this->config->isNewRelicEnabled()) {
$exception = $observer->getEvent()->getException();
$this->newRelicWrapper->reportError($exception);
}
}
}
53 changes: 53 additions & 0 deletions app/code/Magento/NewRelicReporting/Plugin/HttpPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\NewRelicReporting\Plugin;

use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Http;
use Magento\NewRelicReporting\Model\Config;
use Magento\NewRelicReporting\Model\NewRelicWrapper;

class HttpPlugin
{
/**
* @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;
}

/**
* Report exception to New Relic
*
* @param Http $subject
* @param Bootstrap $bootstrap
* @param \Exception $exception
* @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeCatchException(Http $subject, Bootstrap $bootstrap, \Exception $exception)
{
if ($this->config->isNewRelicEnabled()) {
$this->newRelicWrapper->reportError($exception);
}
}
}
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 @@ -27,4 +27,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\App\Http">
<plugin name="framework-http-newrelic" type="Magento\NewRelicReporting\Plugin\HttpPlugin"/>
</type>
</config>

0 comments on commit df7ef2b

Please sign in to comment.