Skip to content

Commit df7ef2b

Browse files
Merge forwardport of #11944 to 2.3-develop branch
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
2 parents ff33a1b + 8161593 commit df7ef2b

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ public function addCustomParameter($param, $value)
2828
return false;
2929
}
3030

31+
/**
32+
* Wrapper for 'newrelic_notice_error' function
33+
*
34+
* @param Exception $exception
35+
* @return void
36+
*/
37+
public function reportError($exception)
38+
{
39+
if (extension_loaded('newrelic')) {
40+
newrelic_notice_error($exception->getMessage(), $exception);
41+
}
42+
}
43+
3144
/**
3245
* Checks whether newrelic-php5 agent is installed
3346
*
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\NewRelicReporting\Model\Observer;
7+
8+
use Magento\Framework\Event\Observer;
9+
use Magento\Framework\Event\ObserverInterface;
10+
use Magento\NewRelicReporting\Model\Config;
11+
use Magento\NewRelicReporting\Model\NewRelicWrapper;
12+
13+
/**
14+
* Class ReportApplicationHandledExceptionToNewRelic
15+
*/
16+
class ReportApplicationHandledExceptionToNewRelic implements ObserverInterface
17+
{
18+
/**
19+
* @var Config
20+
*/
21+
protected $config;
22+
23+
/**
24+
* @var NewRelicWrapper
25+
*/
26+
protected $newRelicWrapper;
27+
28+
/**
29+
* @param Config $config
30+
* @param NewRelicWrapper $newRelicWrapper
31+
*/
32+
public function __construct(
33+
Config $config,
34+
NewRelicWrapper $newRelicWrapper
35+
) {
36+
$this->config = $config;
37+
$this->newRelicWrapper = $newRelicWrapper;
38+
}
39+
40+
public function execute(Observer $observer)
41+
{
42+
if ($this->config->isNewRelicEnabled()) {
43+
$exception = $observer->getEvent()->getException();
44+
$this->newRelicWrapper->reportError($exception);
45+
}
46+
}
47+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\NewRelicReporting\Plugin;
7+
8+
use Magento\Framework\App\Bootstrap;
9+
use Magento\Framework\App\Http;
10+
use Magento\NewRelicReporting\Model\Config;
11+
use Magento\NewRelicReporting\Model\NewRelicWrapper;
12+
13+
class HttpPlugin
14+
{
15+
/**
16+
* @var Config
17+
*/
18+
private $config;
19+
20+
/**
21+
* @var NewRelicWrapper
22+
*/
23+
private $newRelicWrapper;
24+
25+
/**
26+
* @param Config $config
27+
* @param NewRelicWrapper $newRelicWrapper
28+
*/
29+
public function __construct(
30+
Config $config,
31+
NewRelicWrapper $newRelicWrapper
32+
) {
33+
$this->config = $config;
34+
$this->newRelicWrapper = $newRelicWrapper;
35+
}
36+
37+
/**
38+
* Report exception to New Relic
39+
*
40+
* @param Http $subject
41+
* @param Bootstrap $bootstrap
42+
* @param \Exception $exception
43+
* @return void
44+
*
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46+
*/
47+
public function beforeCatchException(Http $subject, Bootstrap $bootstrap, \Exception $exception)
48+
{
49+
if ($this->config->isNewRelicEnabled()) {
50+
$this->newRelicWrapper->reportError($exception);
51+
}
52+
}
53+
}

app/code/Magento/NewRelicReporting/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@
2727
</argument>
2828
</arguments>
2929
</type>
30+
<type name="Magento\Framework\App\Http">
31+
<plugin name="framework-http-newrelic" type="Magento\NewRelicReporting\Plugin\HttpPlugin"/>
32+
</type>
3033
</config>

0 commit comments

Comments
 (0)