apm-agent-php icon indicating copy to clipboard operation
apm-agent-php copied to clipboard

Expected error being overwritten by last thrown exception

Open Nacoma opened this issue 2 years ago • 1 comments

Describe the bug Occasionally when our application throws an exception, the expected error is replaced by a caught exception that is thrown in the error handler.

A basic example of what I'm seeing is that our application will throw

            throw new Exception('Cancellation failed. '.$e->getMessage());

which Laravel reports to Sentry. Sentry has the correct error but this is the exception reported to ELK:

image

However, this exception is caught and ignored in getComposerPackages.

image

To Reproduce I've been unable to replicate this outside of our environment. I will create an application with our exact versions and try to replicate it.

Expected behavior The correct exception is reported.

Nacoma avatar Mar 30 '23 17:03 Nacoma

I've reproduced this in a container in https://github.com/Nacoma/apm-errors-repro.

Can probably run the container with docker compose up -d and trigger the error by visiting localhost:8082. Following the trace logs with docker compose logs you can see that the caught exception is being sent instead of the other.

The changes I made in https://github.com/Nacoma/apm-errors-repro/blob/6883906b3adfc13894106ce3c3e0a99da94fb5fd/app/Exceptions/Handler.php are the main factor it seems.

Nacoma avatar Mar 30 '23 18:03 Nacoma