3636public final class SentryClient implements ISentryClient {
3737 static final String SENTRY_PROTOCOL_VERSION = "7" ;
3838
39+ private static final int LOG_FLUSH_ON_CRASH_TIMEOUT_MILLIS = 500 ;
40+
3941 private boolean enabled ;
4042
4143 private final @ NotNull SentryOptions options ;
@@ -211,16 +213,6 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
211213 sentryId = event .getEventId ();
212214 }
213215
214- final boolean isBackfillable = HintUtils .hasType (hint , Backfillable .class );
215- final boolean isCached =
216- HintUtils .hasType (hint , Cached .class ) && !HintUtils .hasType (hint , ApplyScopeData .class );
217- // if event is backfillable or cached we don't wanna trigger capture replay, because it's
218- // an event from the past. If it's cached, but with ApplyScopeData, it comes from the outbox
219- // folder and we still want to capture replay (e.g. a native captureException error)
220- if (event != null && !isBackfillable && !isCached && (event .isErrored () || event .isCrashed ())) {
221- options .getReplayController ().captureReplay (event .isCrashed ());
222- }
223-
224216 try {
225217 final @ Nullable TraceContext traceContext = getTraceContext (scope , hint , event );
226218 final boolean shouldSendAttachments = event != null ;
@@ -245,6 +237,20 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
245237 finalizeTransaction (scope , hint );
246238 }
247239
240+ final boolean isBackfillable = HintUtils .hasType (hint , Backfillable .class );
241+ final boolean isCached =
242+ HintUtils .hasType (hint , Cached .class ) && !HintUtils .hasType (hint , ApplyScopeData .class );
243+ // if event is backfillable or cached we don't wanna trigger capture replay, because it's
244+ // an event from the past. If it's cached, but with ApplyScopeData, it comes from the outbox
245+ // folder and we still want to capture replay (e.g. a native captureException error)
246+ if (event != null && !isBackfillable && !isCached && (event .isErrored () || event .isCrashed ())) {
247+ options .getReplayController ().captureReplay (event .isCrashed ());
248+ // We need to flush the logs to ensure they are sent on crash
249+ if (event .isCrashed ()) {
250+ loggerBatchProcessor .flush (LOG_FLUSH_ON_CRASH_TIMEOUT_MILLIS );
251+ }
252+ }
253+
248254 return sentryId ;
249255 }
250256
0 commit comments