Laravel - Issues view shows exceptions originating in Middleware instead of the correct class


Hello all,

I have an existing mobile-app API based on Laravel 5.2.

I make a request against an endpoint which passes the request through several Middleware classes after which it arrives at a controller that sends it to a service class that throws an exception.

My problem is that instead of the Issues page in Sentry showing the exception as originating in the service class it shows it as originating in one of the Middleware classes (you’ll notice in the below pic that it seems all my exceptions originate in the same class even though in the code they do not)

Also, when drilling down into a single issue view, the App Only exception display also makes it look like the exception originated in the Middleware class but when I switch the exception display to Full it is clearly shown the exception actually originated in the service class I mentioned before.
(I have screenshots of those views as well, I will upload them in the comments if it helps)

The fact the Issues view misrepresents the actual source of an exception is making it a lot less practical, to me, than it should be.
Has anyone seen this problem before?
Can anyone advise on how to solve this?

P.S. I hope this is in the correct category, I apologize if I made a mistake.



Hey Idan,

This should not be happening but I have an idea why it might.

This service and/or controller, are they not in the “regular” app path but in the vendor folder perhaps?

Sentry scopes error by code inside the app path and outside and I think it sees the origin of the error outside that app path.

It sets the app path based on the base_path() and excludes base_path() . '/vendor' by default.

This might be the issue?


Hey Alex,

It seems that is not the case.
The controller and service which the request goes through are at /project_name/Components/TicketStores/... and so are under the app’s base_path().

The Middleware is under /project_name/app/Http/Middleware/... and so is also under the base_path().


Hey Idan,

I am sorry, the snippet I sent was unreleased at the time… in sentry-laravel <= 0.7.* it was like this:

And since you do not keep your app code under the /app directory (which app_path() resolves to) it doesn’t detect your code properly.

Could you please try and update to 0.8.* of sentry-laravel, that should fix it!


Thanks Alex, it seems to no longer say all exception originate in the same Middleware anymore after this update.
What it does now, though, is show the exception as originating in the same route, like so:


The top Issue is one where I threw the exception in the Controller and the one below it is where I threw an exception in the Service.
Is this intended?


Yes, I believe we extract the route to be able to provide some context from which transaction the error occured, since both were triggered by the same transaction they show as being from the same transaction but are different errors because they originate from 2 different placed in the code, as you mentioned.


OK, thank you very much for your help.