app->singleton(HubInterface::class, function () { $dsn = getenv('GLITCHTIP_DSN'); if (!$dsn) { \Log::warning('SimpleGlitchtip: GLITCHTIP_DSN environment variable is not set.'); return null; } $clientBuilder = ClientBuilder::create([ 'dsn' => $dsn, 'environment' => getenv('APP_ENV') ?: 'production', 'release' => getenv('APP_VERSION') ?: '1.0.0', 'tags' => [ 'application' => 'concrete5', ], ]); return $clientBuilder->getHub(); }); $hub = $this->app->make(HubInterface::class); if ($hub) { $this->attachErrorHandlers(); } else { \Log::warning('SimpleGlitchtip: HubInterface is not initialized. Error reporting is disabled.'); } } private function attachErrorHandlers() { set_exception_handler(function (\Throwable $exception) { $hub = $this->app->make(HubInterface::class); if ($hub) { $eventId = $hub->captureException($exception); \Log::error('SimpleGlitchtip: Sentry Event ID: ' . $eventId); } }); set_error_handler(function ($severity, $message, $file, $line) { if (!(error_reporting() & $severity)) { return false; } $hub = $this->app->make(HubInterface::class); if ($hub) { $exception = new \ErrorException($message, 0, $severity, $file, $line); $eventId = $hub->captureException($exception); \Log::error('SimpleGlitchtip: Sentry Event ID: ' . $eventId); } return true; }); register_shutdown_function(function () { $error = error_get_last(); if ($error !== null && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) { $hub = $this->app->make(HubInterface::class); if ($hub) { $exception = new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']); $eventId = $hub->captureException($exception); \Log::error('SimpleGlitchtip: Sentry Event ID (shutdown error): ' . $eventId); } } }); } }