Connehito / cake-sentry

CakePHP plugin integration for Sentry
MIT License
34 stars 26 forks source link

Catched exceptions are not sent to Sentry #9

Closed jeremyhalin closed 5 years ago

jeremyhalin commented 5 years ago

Should I manually send catched exceptions to Sentry ? Why it's not sent automatically ? I want to know if it's normal behavior. Thanks.

o0h commented 5 years ago

I designed this to "send error and exception to sentry automatically".

This plugin provides "ErrorHandlerMiddleware" and "LogEngine". These class collaborate to handle errors, put data to sentry.

  1. In bootstrap phase, registering ErrorHandlerMiddleware into inner of Cake\Error\Middleware\ErrorHandlerMiddleware.
    • As result, the middleware will access to errors prior to CakePHP's default ErrorHandlerMiddleware.
  2. And in the same phase, LogEngine for error-logging is overloaded
  3. If your app occur some errors, ErrorHandlerMiddleware catch it
  4. Calling by ErrorHandlerMiddleware, LogEngine write out the error to Sentry.

Describing the flow in roughly as bellow.

namespace Connehito\CakeSentry;

use Cake\Error\Middleware\ErrorHandlerMiddleware as CakeErrorHandlerMiddleware;
use Cake\Log\Log;
use Error\Middleware\ErrorHandlerMiddleware;
use Log\Engine\SentryLog; /* LogEngine adapting to Sentry integration */

image


Can you check these points?

  1. Plugin is loaded correctly and enabled?
    • The plugin must be bootstraped
  2. If you use custom ErrorHandler(Middleware) or ErrorLogger, you have to set plugin's one.

Thanks :)

jeremyhalin commented 5 years ago

Thanks for your great explanation.

I added this in config/bootstrap.php

Plugin::load('Connehito/CakeSentry', ['bootstrap' => true]);

I also added this in config/app.php

    'Sentry' => [
        'dsn' => '*****'
    ]

Non catched exceptions are well sent to Sentry, but caught exceptions aren't. Maybe it's normal behavior ? If it is, how can I send them to Sentry ?

o0h commented 5 years ago

Maybe it's normal behavior ?

Your expectation is right, it's different from my intention 😢 Please give me a little time for examine it in detail.

In advance of it, can you tell me some information?

  1. The CakePHP version you use
  2. Configured values for 'Error'
    • It is found in config/app.php or Configure::read('Error')
    • I mean the values set in here
      1. Can you try with disabling debug-mode?
        • set debug to false in here
      2. Sentry.dsn is formatted with https://***(hash)@sentry.io/***(project id) ?

I will reply back once I have more details.

Thanks.

jeremyhalin commented 5 years ago

I'm using CakePHP version 3.6

Here are my values for 'Error' in config.app.php

    'Error' => [
        'errorLevel' => E_ALL,
        'exceptionRenderer' => ExceptionRenderer::class,
        'skipLog' => [],
        'log' => true,
        'trace' => true,
    ],

Changing debug mode is not helping. Plus, when I set debug mode to false, I end up with Internal server error even if I catch the error. And error is not sent to Sentry at all.

Yes Sentry dns is well formatted since it's working without catching error.

jeremyhalin commented 5 years ago

Behavior is so weird, I'm still trying to figure it out 😭

jeremyhalin commented 5 years ago

@o0h Hi, did you have time to investigate issue ? :)

JeremyWinalist commented 5 years ago

Hi @o0h I tried with branch 2.x. It's working for fatal exceptions, but not for notices, warnings and deprecated. Do you have an idea why ? I'm stuck here :(

o0h commented 5 years ago

@JeremyWinalist

Thanks to trying with 2.x branch 😄 Im concerned about Cake's config for Log, Error and PHP's error_handler. Can you show me them?

Log config

Log config handles what and how write log.

After bootstraping your application(e.g. AppController::initialize()), how about your Log config? Please dump it (\Cake\Core\Configure::read('Log')) and post here.

Error config

Error config handles what logs will be output with errorLevel.

As with Log config , please dump it here. (\Cake\Core\Configure::read('Error')).

error_handler

The third point is that php's error(without shutdown) is passed to this plugin's error-handler. You can get it like below.

$handler = set_error_handler(function(){});
$reflection = new ReflectionFunction($handler);
var_dump($reflection->getClosure());
JeremyWinalist commented 5 years ago

Hi, Sorry I couldn't find why this was not working, it's working with basic integration of Sentry Unified SDK. So I'm not using your plugin anymore.

jtraulle commented 4 years ago

When trying the 2.x implementation, I am not getting any exception/error into Sentry as well. Checked every config but I do not know why it is not working. And like JeremyWinalist says, it works also just with Sentry Unified SDK ; this is strange :/

jtraulle commented 4 years ago

@o0h Will it be better if I open a new issue with full context ?

o0h commented 4 years ago

@jtraulle yes, can you open new issue and describe your case in detail?