Skip to content

Commit 5e7fc61

Browse files
author
Oleksii Korshenko
authored
MAGETWO-83600: Report Handled Exceptions To New Relic #11944
2 parents 5de0f07 + 585e040 commit 5e7fc61

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-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: 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)