Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

joshuaziering's avatar

Sentry Not Reporting Additional Context

Hello,

I'm using Sentry Http://GetSentry.com with Laravel 5.1. For various reasons, I'd like to know WHICH of my users caused the exception. The documentation suggests that I only need to pass a second argument to the captureException method. Here's what my [email protected] looks like:

 public function report(Exception $e)
    {
        if ($this->shouldReport($e)) {
            $user = Auth::user();
            app('sentry')->captureException($e,['user' => ['info' => $user]]);

        }
        parent::report($e);
    }

This does not work as expected.

What am I missing?

0 likes
5 replies
joshuaziering's avatar

Sentry support is suggesting that I make a middleware to capture this information and use the user_context method. However it's still not working as expected and I can't see any of the data in the Sentry dashboard.

public function report(Exception $e)
    {
        if(Auth::user())
        {
            //dd(Auth::user()->email);
            app('sentry')->user_context(array(
                'email' => Auth::user()->email
            ));
        }
 
        if ($this->shouldReport($e)) {
            $user = Auth::user();
            app('sentry')->captureException($e,['user' => ['info' => $user]]);
 
        }
        parent::report($e);
    }

joshuaziering's avatar

It also fails to work as a Global middleware as suggested by the documentation:

 class AddUserToSentry
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
 
        if(Auth::user())
        {
            //dd(Auth::user()->email);
            app('sentry')->user_context(array(
                'email' => Auth::user()->email
            ));
        }
        return $next($request);
    }
}
joshuaziering's avatar

Yes, I contacted the excellent SEntry support and they helped me. Apparently I was doing error reporting wrong from an earlier version of Sentry and Laravel. The new stuff gives such beautiful error messages and data. Reach out, they're great.

jmny's avatar

Could you post what you did to fix it? Are you still using a middleware?

Please or to participate in this conversation.