bugsnag / bugsnag-laravel

BugSnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
https://docs.bugsnag.com/platforms/php/laravel/
MIT License
874 stars 129 forks source link

Ability to cancel error notifications before they are sent to Bugsnag #528

Closed OzanKurt closed 1 year ago

OzanKurt commented 1 year ago

Sometimes I have to work actively in staging environment, it is a bit weird that I get every error I see via email as well.

If there were a "pre-notification" callback so that I can return a boolean whether I want the notification to be sent to the Bugsnag server or not.

Bugsnag::beforeNotify(function ($exception, $maybeSomeExtraDataHere): bool {
    // Here I can do whatever I want with the error...
    if (auth()->user() && auth()->user()->id === 1) {
        return false;
    }

    return true;
});

I believe a simple callback like this could have it's use cases.

johnkiely1 commented 1 year ago

Hi @OzanKurt,

You can create a callback as documented here: https://docs.bugsnag.com/platforms/php/laravel/customizing-error-reports/#adding-callbacks

Retuning false will stop the report from being sent to Bugsnag.

Alternatively you can set a release stage and configure it so that reports are only sent when matching a certain release stage. This was way you could ignore reporting everything that happens in staging for example. Details around that are documented here: https://docs.bugsnag.com/platforms/php/laravel/configuration-options/#release-stage

If it is the emails that are the main concern and you do want staging errors to appear in the Bugsnag dashboard you can also configure your email notification settings separately by release stage: https://docs.bugsnag.com/product/email/#filter-settings