|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of Ekino New Relic bundle. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Ekino - Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Ekino\NewRelicBundle\Listener; |
|
15
|
|
|
|
|
16
|
|
|
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; |
|
17
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
18
|
|
|
use Symfony\Component\HttpKernel\Event\ExceptionEvent; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
|
|
|
|
|
|
20
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; |
|
21
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Listen to exceptions dispatched by Symfony to log them to NewRelic. |
|
25
|
|
|
*/ |
|
26
|
|
|
class ExceptionListener implements EventSubscriberInterface |
|
27
|
|
|
{ |
|
28
|
|
|
private $interactor; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(NewRelicInteractorInterface $interactor) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->interactor = $interactor; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public static function getSubscribedEvents(): array |
|
36
|
|
|
{ |
|
37
|
|
|
return [ |
|
38
|
|
|
KernelEvents::EXCEPTION => ['onKernelException', 0], |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param GetResponseForExceptionEvent|ExceptionEvent $event |
|
44
|
|
|
*/ |
|
45
|
|
|
public function onKernelException($event): void |
|
46
|
|
|
{ |
|
47
|
|
|
if (!$event instanceof GetResponseForExceptionEvent && !$event instanceof ExceptionEvent) { |
|
|
|
|
|
|
48
|
|
|
throw new \InvalidArgumentException(\sprintf('Expected instance of type %s, %s given', \class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class, \is_object($event) ? \get_class($event) : \gettype($event))); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$exception = \method_exists($event, 'getThrowable') ? $event->getThrowable() : $event->getException(); |
|
|
|
|
|
|
52
|
|
|
if (!$exception instanceof HttpExceptionInterface) { |
|
53
|
|
|
$this->interactor->noticeThrowable($exception); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths