From 6a07a331379c08b2bd68fc6cfb60fabcff77e9ff Mon Sep 17 00:00:00 2001 From: Dave Earley Date: Wed, 18 Mar 2026 21:17:17 +0000 Subject: [PATCH] chore: update sentry settings --- backend/app/Exceptions/Handler.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/app/Exceptions/Handler.php b/backend/app/Exceptions/Handler.php index 37c7e8f4c..535a9ef47 100644 --- a/backend/app/Exceptions/Handler.php +++ b/backend/app/Exceptions/Handler.php @@ -4,6 +4,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Sentry\Laravel\Facade as Sentry; +use Sentry\State\Scope; use Symfony\Component\Routing\Exception\ResourceNotFoundException as SymfonyResourceNotFoundException; use Throwable; @@ -38,7 +39,30 @@ class Handler extends ExceptionHandler */ public function report(Throwable $e) { - if ($this->shouldReport($e)) { + if ($this->shouldReport($e) && app()->bound('sentry')) { + try { + $user = auth()->user(); + if ($user) { + $ip = request()->ip(); + $isImpersonating = (bool) auth()->payload()->get('is_impersonating', false); + $impersonatorId = $isImpersonating ? auth()->payload()->get('impersonator_id') : null; + + Sentry::configureScope(function (Scope $scope) use ($user, $ip, $isImpersonating, $impersonatorId): void { + $scope->setUser([ + 'id' => $user->id, + 'email' => $user->email, + 'username' => trim($user->first_name . ' ' . $user->last_name), + 'ip_address' => $ip, + ]); + + if ($isImpersonating) { + $scope->setTag('is_impersonating', 'true'); + $scope->setTag('impersonator_id', (string) $impersonatorId); + } + }); + } + } catch (Throwable) { + } Sentry::captureException($e); }