jenssegers / laravel-rollbar

Rollbar error monitoring integration for Laravel projects
329 stars 99 forks source link

Exception stack trace gone in Laravel 5.5 #93

Open zoltanpeto opened 6 years ago

zoltanpeto commented 6 years ago

Hi,

We've recently upgraded our app to Laravel 5.5 and noticed that exceptions are not reported the way they used to be before: the stack trace is completely gone from the report page and only shows the exception message.

After some debugging I realised that it is due to how Laravel's exception handler logs the errors was changed: instead of using the exception instance as the log message (which is then picked up in this package's log listener), it uses the exception message instead and adds the instance itself to the log call's context.

I managed to work around this by adding a \Log::error($exception) call in the app's exception handler report method, but now everything is reported on Rollbar twice: once with and once without the stack trace.

I'm happy to contribute with a PR to fix this issue, let me know!

zoltanpeto commented 6 years ago

To provide some more context of the issue:

L5.4 - Illuminate\Foundation\Exceptions\Handler:

public function report(Exception $e)
{
  if ($this->shouldntReport($e)) {
    return;
  }
  try {
    $logger = $this->container->make(LoggerInterface::class);
  } catch (Exception $ex) {
    throw $e; // throw the original exception
  }
  $logger->error($e);
}

L5.5 - Illuminate\Foundation\Exceptions\Handler:

public function report(Exception $e)
{
  if ($this->shouldntReport($e)) {
    return;
  }

  if (method_exists($e, 'report')) {
    return $e->report();
  }

  try {
    $logger = $this->container->make(LoggerInterface::class);
  } catch (Exception $ex) {
    throw $e; // throw the original exception
  }

  $logger->error(
    $e->getMessage(),
    array_merge($this->context(), ['exception' => $e]
  ));
}
mitchjam commented 6 years ago

I'm experiencing this as well.

EricTendian commented 6 years ago

I'm running into the same issue, did a little digging and I think this might be the offending PR where the change gets introduced: https://github.com/laravel/framework/pull/19698

Just putting it here to provide some more context.

clin407 commented 6 years ago

Any updates to this issue?

ArturMoczulski commented 6 years ago

Hey everyone

This issue has been recently resolved in our officially supported laravel repo: https://github.com/rollbar/rollbar-php-laravel

PR https://github.com/rollbar/rollbar-php-laravel/pull/26 has addressed this.

ralphschindler commented 6 years ago

To understand the original report better, are you saying an app that was created with a 5.4 laravel skeleton has an issue when the framework is updated to 5.5? In new projects that use the 5.5 skeleton (laravel/laravel), I see both the whoops screen and the normal report screen (when whoops is removed), both have the stack trace and the exception message. Additionally, out the box logging (/storage/logs/laravel.log has a stringified version of the exception, as it did before).

It is entirely possible I missed a usage scenario where a 5.4 skeleton using the 5.5 framework might be impacted, and I'd be happy to document what would be expected in the upgrade process to make things work as they previously did.

(For reference, I made the original PR, sorry I am late in seeing this thread. The original PR was made to keep the usage inside laravel consistent to what monolog and psr7 are expecting in their parameters)

victorrss commented 6 years ago

I am using

"php": ">=7.0.0",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"tymon/jwt-auth": "1.0.0-rc.1"

it worked here Add the following code to the render method within app/Exceptions/Handler.php

public function render($request, Exception $e)
    {
        if($e instanceof \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException){
            return response()->json([$e->getMessage()], $e->getStatusCode());
        }
        return parent::render($request, $e);
    }
thecodecafe commented 5 years ago

Don't know if this is still open but in Laravel 5.7 you can use the get trace method on the exception like so. $stacktrace = $exception->getTrace(); This will return the stack trace for you.