Skip to content

Commit a5e99b0

Browse files
committed
set a 500 timeout millis to flush the logs on crash
moved replay capture after sending the crash
1 parent bfc3606 commit a5e99b0

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
public 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,10 +237,18 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
245237
finalizeTransaction(scope, hint);
246238
}
247239

248-
// if event is backfillable or cached we don't need to flush the logs, because it's an event
249-
// from the past. Otherwise we need to flush the logs to ensure they are sent on crash
250-
if (event != null && !isBackfillable && !isCached && event.isCrashed()) {
251-
loggerBatchProcessor.flush(options.getFlushTimeoutMillis());
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+
}
252252
}
253253

254254
return sentryId;

sentry/src/test/java/io/sentry/SentryClientTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ class SentryClientTest {
30393039
listOf(SentryException().apply { mechanism = Mechanism().apply { isHandled = false } })
30403040
}
30413041
)
3042-
verify(batchProcessor).flush(any())
3042+
verify(batchProcessor).flush(eq(500))
30433043
}
30443044

30453045
@Test

0 commit comments

Comments
 (0)