Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 2cc85a1

Browse files
committed
Listen for exceptions and report to New Relic
1 parent debea42 commit 2cc85a1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
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+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
<observer name="newrelicreporting_observer_report_sales_order_place" instance="Magento\NewRelicReporting\Model\Observer\ReportOrderPlaced" />
1111
<observer name="newrelicreporting_newrelic_report_sales_order_place" instance="Magento\NewRelicReporting\Model\Observer\ReportOrderPlacedToNewRelic" />
1212
</event>
13+
<event name="application_handled_exception">
14+
<observer name="newrelicreporting_newrelic_report_application_handled_exception" instance="Magento\NewRelicReporting\Model\Observer\ReportApplicationHandledExceptionToNewRelic" />
15+
</event>
1316
</config>

0 commit comments

Comments
 (0)