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
10 changes: 10 additions & 0 deletions src/Sentry/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sentry\Laravel;

use Sentry\Logs\Logs;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Events\Dispatcher;
Expand Down Expand Up @@ -163,6 +164,15 @@ protected function bindEvents(): void
if (isset($userConfig['send_default_pii']) && $userConfig['send_default_pii'] !== false) {
$handler->subscribeAuthEvents($dispatcher);
}

if (isset($userConfig['enable_logs']) && $userConfig['enable_logs'] === true && method_exists($this->app, 'terminating')) {
// Listen to the terminating event to flush the logs before the application ends
// This ensures that all logs are sent to Sentry even if the application ends unexpectedly
// We need to check for method existence here for Lumen since this method was only introduced in Lumen 9.1.4
$this->app->terminating(static function () {
Logs::getInstance()->flush();
});
}
} catch (BindingResolutionException $e) {
// If we cannot resolve the event dispatcher we also cannot listen to events
}
Expand Down