Skip to content

Commit d59a334

Browse files
authored
Merge bfc3606 into 85d7417
2 parents 85d7417 + bfc3606 commit d59a334

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
- Replace `UUIDGenerator` implementation with Apache licensed code ([#4662](https://github.com/getsentry/sentry-java/pull/4662))
1010
- Replace `Random` implementation with MIT licensed code ([#4664](https://github.com/getsentry/sentry-java/pull/4664))
1111

12+
### Fixes
13+
14+
- Flush logs on crash ([#4684](https://github.com/getsentry/sentry-java/pull/4684))
15+
1216
## 8.20.0
1317

1418
### Fixes

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
245245
finalizeTransaction(scope, hint);
246246
}
247247

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());
252+
}
253+
248254
return sentryId;
249255
}
250256

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,6 +3023,25 @@ class SentryClientTest {
30233023
assertTrue(terminated == true)
30243024
}
30253025

3026+
@Test
3027+
fun `flush logs for crash events`() {
3028+
val sut = fixture.getSut()
3029+
val batchProcessor = mock<ILoggerBatchProcessor>()
3030+
sut.injectForField("loggerBatchProcessor", batchProcessor)
3031+
sut.captureLog(
3032+
SentryLogEvent(SentryId(), SentryNanotimeDate(), "message", SentryLogLevel.WARN),
3033+
fixture.scopes.scope,
3034+
)
3035+
3036+
sut.captureEvent(
3037+
SentryEvent().apply {
3038+
exceptions =
3039+
listOf(SentryException().apply { mechanism = Mechanism().apply { isHandled = false } })
3040+
}
3041+
)
3042+
verify(batchProcessor).flush(any())
3043+
}
3044+
30263045
@Test
30273046
fun `cleans up replay folder for Backfillable replay events`() {
30283047
val dir = File(tmpDir.newFolder().absolutePath)

0 commit comments

Comments
 (0)