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

Add ability to discard events based on class/error names #622

Merged
merged 5 commits into from Feb 3, 2021

Conversation

imjoehaines
Copy link
Member

Goal

Adds a "discard classes" configuration option that allows events to be discarded based on the exception class name or error name. By default, no events will be discarded

This accepts fully qualified class names and regular expressions. For example, to discard both UnderflowException and OverflowExceptions, either of the following would work:

$bugsnag->setDiscardClasses([
    \UnderflowException::class,
    \OverflowException::class,
]);

or

$bugsnag->setDiscardClasses([
    '/^(Under|Over)flowException$/',
]);

PHP errors (warnings, notices etc...) can also be discarded by the name displayed in the dashboard; this can be obtained using the \Bugsnag\ErrorTypes::getName method. For example, to discard all PHP notices:

$bugsnag->setDiscardClasses([
    \Bugsnag\ErrorTypes::getName(E_NOTICE),
]);

As with exceptions, regexes can also be used:

$bugsnag->setDiscardClasses([
    '/Notice/',
]);

Discarding applies to the entire exception chain, for example if LogicException is a discarded class, then a RuntimeException that wraps a LogicException will also be discarded:

$bugsnag->setDiscardClasses([
    \LogicException::class
]);

// Would be discarded:
throw new RuntimeException('', 0, new LogicException());

// Would _not_ be discarded:
throw new RuntimeException();

NB: the same list is applied to exceptions and PHP errors, so regexes that are too loose can discard more than intended

Changeset

  • discardClasses configuration option with getters & setters in Client & Configuration
  • DiscardClasses middleware which does the discarding (added by default in the Client constructor)
  • Report::getErrors added as a way to get the full list of errors (i.e. including previous exceptions) in a standardised structure
  • Unit tests

@imjoehaines imjoehaines marked this pull request as ready for review February 3, 2021 15:30
@imjoehaines imjoehaines merged commit 1364efe into next Feb 3, 2021
@imjoehaines imjoehaines deleted the discard-classes branch August 24, 2021 08:45
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

Successfully merging this pull request may close these issues.

None yet

2 participants