File tree Expand file tree Collapse file tree 3 files changed +53
-9
lines changed
app/code/Magento/GraphQlNewRelic Expand file tree Collapse file tree 3 files changed +53
-9
lines changed Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \GraphQlNewRelic \Plugin ;
9
9
10
- use Magento \Framework \GraphQl \Exception \ExceptionFormatter ;
10
+ use GraphQL \Error \Error ;
11
+ use Magento \Framework \GraphQl \Query \ErrorHandler ;
11
12
use Magento \NewRelicReporting \Model \NewRelicWrapper ;
12
13
13
14
/**
@@ -24,18 +25,17 @@ public function __construct(private NewRelicWrapper $newRelicWrapper) {
24
25
/**
25
26
* Sends error from GraphQL to New Relic
26
27
*
27
- * @param ExceptionFormatter $subject
28
- * @param \Throwable $exception
29
- * @param string|null $internalErrorMessage
28
+ * @param ErrorHandler $subject
29
+ * @param Error[] $errors
30
+ * @param callable $formatter
30
31
* @return null
31
32
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
32
33
*/
33
- public function beforeCheck (
34
- ExceptionFormatter $ subject ,
35
- \Throwable $ exception ,
36
- string $ internalErrorMessage = null
34
+ public function beforeHandle (ErrorHandler $ subject , array $ errors , callable $ formatter
37
35
): null {
38
- $ this ->newRelicWrapper ->reportError ($ exception );
36
+ if (!empty ($ errors )) {
37
+ $ this ->newRelicWrapper ->reportError ($ errors [0 ]); // Note: We only log the first error because performance
38
+ }
39
39
return null ;
40
40
}
41
41
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQlNewRelic \Plugin ;
9
+
10
+ use Magento \Framework \GraphQl \Exception \ExceptionFormatter ;
11
+ use Magento \NewRelicReporting \Model \NewRelicWrapper ;
12
+
13
+ /**
14
+ * Plugin that sends GraphQL Errors to New Relic
15
+ */
16
+ class ReportException
17
+ {
18
+ /**
19
+ * @param NewRelicWrapper $newRelicWrapper
20
+ */
21
+ public function __construct (private NewRelicWrapper $ newRelicWrapper ) {
22
+ }
23
+
24
+ /**
25
+ * Sends error from GraphQL to New Relic
26
+ *
27
+ * @param ExceptionFormatter $subject
28
+ * @param \Throwable $exception
29
+ * @param string|null $internalErrorMessage
30
+ * @return null
31
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
32
+ */
33
+ public function beforeCheck (
34
+ ExceptionFormatter $ subject ,
35
+ \Throwable $ exception ,
36
+ string $ internalErrorMessage = null
37
+ ): null {
38
+ $ this ->newRelicWrapper ->reportError ($ exception );
39
+ return null ;
40
+ }
41
+ }
Original file line number Diff line number Diff line change 14
14
</arguments >
15
15
</type >
16
16
<type name =" Magento\Framework\GraphQl\Exception\ExceptionFormatter" >
17
+ <plugin name =" report-exception-to-new-relic" type =" Magento\GraphQlNewRelic\Plugin\ReportException" sortOrder =" 50" />
18
+ </type >
19
+ <type name =" Magento\Framework\GraphQl\Query\ErrorHandler" >
17
20
<plugin name =" report-error-to-new-relic" type =" Magento\GraphQlNewRelic\Plugin\ReportError" sortOrder =" 50" />
18
21
</type >
19
22
</config >
You can’t perform that action at this time.
0 commit comments