File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace Sentry \Laravel ;
44
5+ use Sentry \Logs \Logs ;
56use Illuminate \Contracts \Config \Repository ;
67use Illuminate \Contracts \Container \BindingResolutionException ;
78use Illuminate \Contracts \Events \Dispatcher ;
@@ -163,6 +164,15 @@ protected function bindEvents(): void
163164 if (isset ($ userConfig ['send_default_pii ' ]) && $ userConfig ['send_default_pii ' ] !== false ) {
164165 $ handler ->subscribeAuthEvents ($ dispatcher );
165166 }
167+
168+ if (isset ($ userConfig ['enable_logs ' ]) && $ userConfig ['enable_logs ' ] === true && method_exists ($ this ->app , 'terminating ' )) {
169+ // Listen to the terminating event to flush the logs before the application ends
170+ // This ensures that all logs are sent to Sentry even if the application ends unexpectedly
171+ // We need to check for method existence here for Lumen since this method was only introduced in Lumen 9.1.4
172+ $ this ->app ->terminating (static function () {
173+ Logs::getInstance ()->flush ();
174+ });
175+ }
166176 } catch (BindingResolutionException $ e ) {
167177 // If we cannot resolve the event dispatcher we also cannot listen to events
168178 }
You can’t perform that action at this time.
0 commit comments