bugsnag / bugsnag-php

BugSnag error monitoring and crash reporting tool for PHP apps
https://docs.bugsnag.com/platforms/php
MIT License
554 stars 77 forks source link

Option to disable syslog() call #644

Closed alcohol closed 2 years ago

alcohol commented 2 years ago

Description

Option to disable the syslog() call in Bugsnag\Middleware\DiscardClasses.

Describe the solution you'd like

A configuration flag to enable/disable the syslog call.

Describe alternatives you've considered

Patching vendor/ files... please no.

Additional context

Would be nice to have, not must have.

yousif-bugsnag commented 2 years ago

Hi @alcohol, thanks for the suggestion! Can you tell us a little more about why you think this feature would be useful? For example are you getting spammed with large numbers of these log messages?

alcohol commented 2 years ago

Yeah, unfortunately. My client has a legacy application that needs a lot of patching and fixing, and this noise is making it a bit awkward to spot other issues.

We only discard the following classes in my client's codebase:

- Symfony\Component\HttpKernel\Exception\NotFoundHttpException
- Symfony\Component\Security\Core\Exception\AccessDeniedException
- Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException

But if I peek at the log of the php-fpm service on our servers using journalctl I basically just see a flood of these:

Mar 03 09:49:08 <hostname> php-fpm8.1[1442507]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:49:08 <hostname> php-fpm8.1[1442640]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:49:38 <hostname> php-fpm8.1[1443398]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:49:38 <hostname> php-fpm8.1[1442843]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:49:40 <hostname> php-fpm8.1[1443398]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:49:54 <hostname> php-fpm8.1[1443620]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:49:54 <hostname> php-fpm8.1[1443398]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:49:54 <hostname> php-fpm8.1[1442640]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:50:02 <hostname> php-fpm8.1[1442507]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:50:03 <hostname> php-fpm8.1[1442843]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:03 <hostname> php-fpm8.1[1442640]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:04 <hostname> php-fpm8.1[1442507]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:04 <hostname> php-fpm8.1[1443620]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:04 <hostname> php-fpm8.1[1443398]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:04 <hostname> php-fpm8.1[1442843]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:04 <hostname> php-fpm8.1[1443620]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:04 <hostname> php-fpm8.1[1442508]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:08 <hostname> php-fpm8.1[1442650]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:50:08 <hostname> php-fpm8.1[1443620]: ool fpm: Discarding event because error class "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" matched discardClasses configuration
Mar 03 09:50:10 <hostname> php-fpm8.1[1442843]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:10 <hostname> php-fpm8.1[1442507]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:11 <hostname> php-fpm8.1[1443887]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
Mar 03 09:50:11 <hostname> php-fpm8.1[1442843]: ool fpm: Discarding event because error class "Symfony\Component\Security\Core\Exception\AccessDeniedException" matched discardClasses configuration
yousif-bugsnag commented 2 years ago

Got it, thanks for the additional details. You should be able to achieve that by removing your discardClasses configuration and instead registering your own callback to check for and discard these errors without the syslog call.

The callback gets added to the middleware pipeline and is passed a $report object so you could do something similar to the internal middleware implementation and simply return false from the callback to discard the report: https://github.com/bugsnag/bugsnag-php/blob/ad2b40ba8a512d9b19ed0ff8fab169184d3eb775/src/Middleware/DiscardClasses.php#L31-L46

alcohol commented 2 years ago

Ah, did not think of that myself. Cheers, that's an acceptable alternative.