Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion backend/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
Loading