added glitchtip using sentry sdk

This commit is contained in:
Codex Agent
2025-12-19 10:13:30 +01:00
parent 53ec427e6e
commit 778ffc8bb9
13 changed files with 1574 additions and 58 deletions

View File

@@ -10,9 +10,12 @@ use Illuminate\Http\Client\ConnectionException as HttpClientConnectionException;
use Illuminate\Queue\InvalidQueueException;
use Illuminate\Queue\MaxAttemptsExceededException;
use Illuminate\Routing\Exceptions\InvalidSignatureException;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use League\Flysystem\FilesystemException;
use PDOException;
use Sentry\State\Scope;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Throwable;
class Handler extends ExceptionHandler
@@ -34,7 +37,17 @@ class Handler extends ExceptionHandler
public function register(): void
{
$this->reportable(function (Throwable $e) {
//
if ($this->shouldSkipSentry($e)) {
return;
}
if (! app()->bound('sentry') || empty(config('sentry.dsn'))) {
return;
}
$this->configureSentryScope();
app('sentry')->captureException($e);
});
}
@@ -90,6 +103,58 @@ class Handler extends ExceptionHandler
return parent::render($request, $e);
}
private function configureSentryScope(): void
{
\Sentry\configureScope(function (Scope $scope): void {
$user = Auth::user();
if ($user) {
$userData = [
'id' => (string) $user->getAuthIdentifier(),
];
if (! empty($user->email)) {
$userData['email'] = $user->email;
}
if (! empty($user->username)) {
$userData['username'] = $user->username;
}
$scope->setUser($userData);
if (! empty($user->tenant_id)) {
$scope->setTag('tenant_id', (string) $user->tenant_id);
}
if (! empty($user->role)) {
$scope->setTag('user_role', $user->role);
}
}
});
}
private function shouldSkipSentry(Throwable $throwable): bool
{
if ($throwable instanceof ValidationException) {
return true;
}
$status = null;
if ($this->isHttpException($throwable)) {
$status = $this->toHttpException($throwable)->getStatusCode();
} elseif ($throwable instanceof HttpExceptionInterface) {
$status = $throwable->getStatusCode();
}
if (is_int($status) && $status < 500 && $status !== 429) {
return true;
}
return false;
}
private function buildGenericMessage(int $status): string
{
if ($status >= 500) {