Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Exception becomes two occurences in Rollbar app #36

Closed
hngl opened this issue Oct 8, 2018 · 3 comments
Closed

Uncaught Exception becomes two occurences in Rollbar app #36

hngl opened this issue Oct 8, 2018 · 3 comments
Assignees

Comments

@hngl
Copy link

hngl commented Oct 8, 2018

When using a basic Symfony 4 setup with the setup of the bundle as described in the Rollbar Symfony docs, one Exception thrown becomes 2 lines in the occurrences table.

trace.exception.message custom.channel custom.datetime custom.level custom.payload.body.trace_chain
Example msg app 1539001010 error [{"frames":...
Example msg request 1539001009 critical (empty)

Setup

config/bundles.php

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
    Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
   /* ... */
   
	// RollbarBundle must be included _after_ MonologBundle
    Rollbar\Symfony\RollbarBundle\RollbarBundle::class => ['prod' => true],
];

config/packages/prod/rollbar.yaml

rollbar:
  enabled: true
  access_token: '%env(ROLLBAR_TOKEN)%'
  environment: '%env(APP_HOST)%'

config/packages/monolog.yaml

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error # log all errors with status code >= 400
            handler:      grouped
        grouped:
            type:    group
            members: [streamed, deduplicated]
        streamed:
            type:  stream
            path:  '%kernel.logs_dir%/%kernel.environment%.log'
            level: error
        deduplicated:
            type:    deduplication
            handler: swift
        swift:
            type:       swift_mailer
            from_email: 'noreply@example.org'
            to_email:   '%env(SERVER_ADMIN)%'
            subject:    '%%message%%'
            level:      notice
            formatter:  monolog.formatter.html
            content_type: text/html

config/packages/prod/monolog.yaml

monolog:
  handlers:
    # This appends `rollbar` to the environment-independent list of handlers
    rollbar:
      type: service
      id: Rollbar\Monolog\Handler\RollbarHandler
@hngl
Copy link
Author

hngl commented Oct 8, 2018

After some more testing, I can make the following distinction.

Errors logged via a call to Monolog, are logged once.

 $psrLogger->error('Testing Rollbar', ['someVar' => 'someValue']);

Uncaught Exceptions are logged twice.

throw new TestingRollbarException('Is this thing on?');

@hngl hngl changed the title One Exception becomes two occurences in Rollbar app Uncaught Exception becomes two occurences in Rollbar app Oct 8, 2018
@hngl
Copy link
Author

hngl commented Oct 9, 2018

The problem is caused by having the bundle register listeners for the kernel.exception event, in addition to Symfony listeners, which log to Monolog.

Symfony standard registers the Symfony\Component\HttpKernel\EventListener\ExceptionListener::logKernelException() listener. This listener sends the exception to the default logger . That is usually Monolog.

Output of bin/console debug:event-dispatcher kernel.exception:

"kernel.exception" event
------------------------

 ------- ------------------------------------------------------------------------------------ ----------
  Order   Callable                                                                             Priority
 ------- ------------------------------------------------------------------------------------ ----------
  #1      App\Api\EventSubscriber\ApiExceptionSubscriber::handleApiException()                 2049
  #2      App\EventSubscriber\AccountExceptionSubscriber::handleUnknownAccountException()      3
  #3      App\EventSubscriber\AccountExceptionSubscriber::handleExpiredAccountException()      2
  #4      Rollbar\Symfony\RollbarBundle\EventListener\ErrorListener::onKernelException()       0
  #5      Symfony\Component\HttpKernel\EventListener\ExceptionListener::logKernelException()   0
  #6      Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onException()    0
  #7      Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelException()       -64
  #8      Rollbar\Symfony\RollbarBundle\EventListener\ExceptionListener::onKernelException()   -100
  #9      Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException()    -128
 ------- ------------------------------------------------------------------------------------ ----------

That is how when using this SDK, uncaught exceptions show up twice in Rollbar.

@ArturMoczulski Could you please remove the listeners?

@ArturMoczulski
Copy link

@hngl thank you for PR. I merged it in. phpunit exiting with a non-zero status will be resolved as a separate issue since I identified the problem happening in the master branch as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants