Sentry-laravel: Two Sentry issues for one exception

Created on 4 Aug 2019  路  23Comments  路  Source: getsentry/sentry-laravel

Ever since upgrading from 1.0.0-beta2 to 1.1.0 I am sometimes seeing two issues for a single exception, one prefaced with Notice:. This was one I created:

image

This could be happening every time, but I'm not sure as I am 2 days from launch. Is this from upgrading or something on my end?

At the time of upgrade I also stopped receiving emails for Laravel issues (but still get JS emails). I have checked my settings (that I didn't ever change) and they look correct to alert me. Anyone else?

support

Most helpful comment

sentry/sentry-laravel 1.6.2 was just released which fixes the regression causing duplicate exceptions, thanks all for the information and patience!

All 23 comments

@futzlarson Are you using the log channel integration next to the "normal" integration by any chance?

@stayallive Honestly I don't know what you're asking.

@futzlarson there are 2 ways to integrate Sentry with Laravel.

This first is the recommended way: https://docs.sentry.io/platforms/php/laravel/#laravel-5x

The second is by using a so called log channel (a Laravel feature): https://docs.sentry.io/platforms/php/laravel/#using-laravel-56-log-channels

Using both can cause doubled errors, so I am wondering if you maybe have both setup in your application if not we will have to take a deeper look why this is happening, if you did setup both that explains it because if you鈥檙e using log channels to log your exceptions and are also logging exceptions to Sentry in your exception handler (as you would have configured above) exceptions might end up twice in Sentry.

@futzlarson @stayallive I've been investigating through this issue recently, since we don't use the Laravel report function nor does the Log function.
We send sentry specifically in a try catch block manually. However, ever since updating 1.0.0-beta2, we've been stepping up on this issue of duplicate Log or receiving sentry notifications even if we caught the error/exception/throwable.

I think the code that has problem is here in sentry-php:
https://github.com/getsentry/sentry-php/blob/78495dd5cd68b1a01a864c1e4019556ed7a3962e/src/ErrorHandler.php#L174

This overrides the default Laravel set_error_handler() (https://github.com/laravel/framework/blob/195dba7ea2a68d3a49593d0de0df73c12a59fc72/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php#L43)
no matter what, and handle the issue itself.

Therefore for the example @futzlarson is posting: will always have two sent to sentry, one from Laravel Log/Report and one for sentry-php itself

@marandy0905 the set_error_handler does not trigger for exceptions.

So it's possibly your code generates a exception but also a notice or warning (error) and you are capturing the Exception and Sentry is capturing the error?

Could you share both errors like the screenshot from Ryan with what you are getting?

@marandy0905 Also please update to the latest version, we are at 1.1.0 so we are talking about the same code, a lot of things we're fixed in the beta's.

@stayallive I think I mentioned it the wrong way. But you are absolutely right about this:

So it's possibly your code generates an exception but also a notice or warning (error) and you are capturing the Exception and Sentry is capturing the error?

The problem is that Laravel already help us catch this kind of error/notice with it's own set_error_handler() in the link provided above and re-throw it as an ErrorException class.

I'll show some pseudo code below with a simple API:

 // Set up 'report' or Log::error(); depends on your setting of sentry in Laravel

Route::get('health', function () {
    try {
        $data = [];
        $data['test'];
    } catch (\Throwable $th) {
        var_dump(get_class($th)); // 'ErrorException' 

        return response('un-oh');
    }

    return response('ok');
});

With the above example,
EXPECT: Receiving an 'un-oh' response, sending an ErrorException notification to Sentry.
ACTUAL: Receiving an 'un-oh' response, sent a notice error and an ErrorException notification to Sentry. The latter is triggered by the report function in App/Exceptions/Handler.php as suggested by the official Doc in Sentry.

Since Laravel already has a fallback solution for reporting all notice/warning, Sentry-php is still
intercepting the error_handler setting causing to sent to sentry twice.

btw, I'm working on 1.1.0 right now, and 5.8 for Laravel, the problem actually just happens starting from 1.0.0-beta2, there's a major change of how error_handler is set since then.

铻㈠箷蹇収 2019-08-22 涓嬪崍5 47 48

more info: we're not using any Log or report function but handle Send Sentry in our own middleware.

However a fresh install of Laravel with either (only one) place implementing Sentry will reproduce.

And also we figured out to close sending to sentry by setting 'error_type' => 0 in sentry config. This works well by not sending the unexpected notice/warning but still send the ErrorException one.

@stayallive FYI I am only doing the recommended way. And as @marandy0905 mentioned, this only started happening once I upgraded. Side note, it doesn't seem to happen every time.

Any update @stayallive?

Guys, that's because of Sentry's integrations. They handle errors before laravel's handler does it.

@SCIF But this is something that only started happening in recent versions?

Probably this one introduced it. Not sure. I still doesn't have enough time to investigate that.

Sentry registers it's own error handler, which reports given error.
And runs previous error handler after, which might throw an exception, like in Laravel HandleExceptions. That last exception is also reported by Sentry.

probably can be fixed with sentry.php config:

<?php

return [
    'error_types' => ~E_ALL,
];

I found that, client builder have default integration of ExceptionListenerIntegration which register error handler. So put captureException in error handler or add logging in application will duplicate log.

We are working on seeing if #280 solves the issue which is most likely the best "fix" for the issue without us missing issues (takes a bit of time to test).

I try #280 and it fixed duplicate log. I'll wait for release. For now, I'll remove captureError on laravel handler.

This issue was closed however I never mentioned we think it's fixed in 1.4.0, please do open it back up or open a new issue if the problem is not solved.

1.4.1 is working fine for me - thanks!

I have recently started seing double exceptions being reported again now recently. Is this just me, or was something changed in 1.6.X perhaps?

@carestad We've also been seeing issue this again.

The regression seems to be caused by sentry-php 2.3. I forced "sentry/sentry-laravel": "1.5.*" and switched between "sentry/sentry": "2.2.*" and 2.3.*, calling return 1/0; on 2.2 sends one error to Sentry, but on 2.3 I get two.

Yes, as mentioned in #327 this problem is caused by sentry/sentry:^2.3 and will be fixed shortly for now pinning to sentry/sentry-laravel:1.5.* and sentry/sentry:2.2.* is a immediate fix if you need it.

sentry/sentry-laravel 1.6.2 was just released which fixes the regression causing duplicate exceptions, thanks all for the information and patience!

Was this page helpful?
0 / 5 - 0 ratings