Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

kernel.exception is not triggered when (e.g.) new relic registers an error handler #25827

Copy link
Copy link
Closed
@linaori

Description

@linaori
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4 (probably lower as well)

After @nicolas-grekas dug in this for me on slack, it turns out that the Symfony error handler is not registered because new relic already registers on.

Related issue seems to be an old one: https://discuss.newrelic.com/t/how-to-disable-newrelic-set-exception-handler/35544/16

Snippet of our discussion on Slack:

in dev, Debug::enable() always installs Debug::ErrorHandler()
so that DebugHandlersListener is able to register the required logic
in prod, ErrorHandler::register() is called in FrameworkBundle::boot()
but with $replace=false as second argument
so that with new relic, no registration happen
making DebugHandlersListener a no-op
I'm now wondering if ErrorHandler's line L135 shouldn't be unconditional
the decoration is seamless I think

It seems that exceptions are still caught, as long as they are custom exceptions. Fatal errors (and possibly core exceptions) are not caught.

PHP Fatal error:  Uncaught Symfony\\Component\\Debug\\Exception\\FatalThrowableError: Cannot use object of type Hostnet\\App\\Component\\Security\\Authentication\\Oauth\\OauthCredentials as array in /home/prod/mijn/12.17.7____0/src/App/EventListener/Security/StoreLoginLog.php:86\nStack trace:\n#0 /home/prod/mijn/12.17.7____0/vendor/symfony/event-dispatcher/EventDispatcher.php(212): Hostnet\\App\\EventListener\\Security\\StoreLoginLog->onAuthenticationFailure(Object(Symfony\\Component\\Security\\Core\\Event\\AuthenticationFailureEvent), 'security.authen...', Object(Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher))\n#1 /home/prod/mijn/12.17.7____0/vendor/symfony/event-dispatcher/EventDispatcher.php(44): Symfony\\Component\\EventDispatcher\\EventDispatcher->doDispatch(Array, 'security.authen...', Object(Symfony\\Component\\Security\\Core\\Event\\AuthenticationFailureEvent))\n#2 /home/prod/mijn/12.17.7____0/vendor/symfony/security/Core/Authentication/AuthenticationProviderManager.php(107): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispa in /home/prod/mijn/12.17.7____0/src/App/EventListener/Security/StoreLoginLog.php on line 86, referer: https://accounts.google.com/...
PHP Stack trace:, referer: https://accounts.google.com/...
PHP   1. Symfony\\Component\\Debug\\ErrorHandler->handleException() /home/prod/mijn/12.17.7____0/vendor/symfony/debug/ErrorHandler.php:0, referer: https://accounts.google.com/...
PHP   2. newrelic_exception_handler() /home/prod/mijn/12.17.7____0/vendor/symfony/debug/ErrorHandler.php:538, referer: https://accounts.google.com/signin/oauth/...

The class logging this (similar to the class that's redirecting it), are registered on the kernel.exception event (which is no longer triggered):

// ...
final class UncaughtExceptionLogger implements EventSubscriberInterface
{
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function onKernelException(GetResponseForExceptionEvent $event): void
    {
        $e = $event->getException()
        $this->logger->error('Uncaught PHP Exception: ' . \get_class($e), ['exception' => $e]);
    }

    public static function getSubscribedEvents(): array
    {
        return [KernelEvents::EXCEPTION => ['onKernelException', -16]];
    }
}

In result with new relic:

  • app.php: white 500 webserver error page, kernel.exception is not triggered
  • app_dev.php: working as intended
  • apache error logging work fine
  • new relic error logging works fine

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.