Skip to content

Commit

Permalink
Merge pull request #243 from teohhanhui/fix/error-listener-hub-instan…
Browse files Browse the repository at this point in the history
…tiation

Fix ErrorListener not capturing events when Hub is not instantiated yet
  • Loading branch information
Jean85 committed Sep 23, 2019
2 parents cb49aba + 12ff6ad commit 4f4dcf0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/EventListener/ErrorListener.php
Expand Up @@ -2,12 +2,25 @@

namespace Sentry\SentryBundle\EventListener;

use Sentry\State\HubInterface;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;

final class ErrorListener
{
/** @var HubInterface */
private $hub;

/**
* ErrorListener constructor.
* @param HubInterface $hub
*/
public function __construct(HubInterface $hub)
{
$this->hub = $hub; // not used, needed to trigger instantiation
}

public function onKernelException(GetResponseForExceptionEvent $event): void
{
\Sentry\captureException($event->getException());
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Expand Up @@ -28,6 +28,7 @@
</service>

<service id="Sentry\SentryBundle\EventListener\ErrorListener" class="Sentry\SentryBundle\EventListener\ErrorListener" public="false">
<argument type="service" id="Sentry\State\HubInterface" />
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="%sentry.listener_priorities.request_error%" />
<!-- The following tag is done manually in PHP for BC with Symfony < 3.3 -->
<!-- <tag name="kernel.event_listener" event="console.error" method="onConsoleError" priority="%sentry.listener_priorities.console_error%" />-->
Expand Down

0 comments on commit 4f4dcf0

Please sign in to comment.