diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da8060b6b..6e6820a9a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Common: Finalize previous session even when auto session tracking is disabled ([#5154](https://github.com/getsentry/sentry-java/pull/5154)) - Android: Add proguard rules to prevent error about missing Replay classes ([#5153](https://github.com/getsentry/sentry-java/pull/5153)) ## 8.34.0 diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java b/sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java index cae558f0d4..2779f803a6 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java @@ -1,7 +1,6 @@ package io.sentry.android.core; import static io.sentry.Sentry.getCurrentScopes; -import static io.sentry.SentryLevel.DEBUG; import static io.sentry.SentryLevel.INFO; import static io.sentry.SentryLevel.WARNING; @@ -291,13 +290,6 @@ private static void deleteCurrentSessionFile(final @NotNull SentryOptions option return; } - if (!options.isEnableAutoSessionTracking()) { - options - .getLogger() - .log(DEBUG, "Session tracking is disabled, bailing from deleting current session file."); - return; - } - final File sessionFile = EnvelopeCache.getCurrentSessionFile(cacheDirPath); if (!sessionFile.delete()) { options.getLogger().log(WARNING, "Failed to delete the current session file."); diff --git a/sentry/src/main/java/io/sentry/MovePreviousSession.java b/sentry/src/main/java/io/sentry/MovePreviousSession.java index 99b92d9265..6b7de16d81 100644 --- a/sentry/src/main/java/io/sentry/MovePreviousSession.java +++ b/sentry/src/main/java/io/sentry/MovePreviousSession.java @@ -1,6 +1,5 @@ package io.sentry; -import static io.sentry.SentryLevel.DEBUG; import static io.sentry.SentryLevel.INFO; import io.sentry.cache.EnvelopeCache; @@ -24,13 +23,6 @@ public void run() { return; } - if (!options.isEnableAutoSessionTracking()) { - options - .getLogger() - .log(DEBUG, "Session tracking is disabled, bailing from previous session mover."); - return; - } - final IEnvelopeCache cache = options.getEnvelopeDiskCache(); if (cache instanceof EnvelopeCache) { final File currentSessionFile = EnvelopeCache.getCurrentSessionFile(cacheDirPath); diff --git a/sentry/src/main/java/io/sentry/PreviousSessionFinalizer.java b/sentry/src/main/java/io/sentry/PreviousSessionFinalizer.java index 46e0c25850..4e3b2e9b3d 100644 --- a/sentry/src/main/java/io/sentry/PreviousSessionFinalizer.java +++ b/sentry/src/main/java/io/sentry/PreviousSessionFinalizer.java @@ -48,13 +48,6 @@ public void run() { return; } - if (!options.isEnableAutoSessionTracking()) { - options - .getLogger() - .log(DEBUG, "Session tracking is disabled, bailing from previous session finalizer."); - return; - } - final IEnvelopeCache cache = options.getEnvelopeDiskCache(); if (cache instanceof EnvelopeCache) { if (!((EnvelopeCache) cache).waitPreviousSessionFlush()) { diff --git a/sentry/src/test/java/io/sentry/MovePreviousSessionTest.kt b/sentry/src/test/java/io/sentry/MovePreviousSessionTest.kt index 0c361c3efe..f14cbd6d01 100644 --- a/sentry/src/test/java/io/sentry/MovePreviousSessionTest.kt +++ b/sentry/src/test/java/io/sentry/MovePreviousSessionTest.kt @@ -65,13 +65,21 @@ class MovePreviousSessionTest { } @Test - fun `when session tracking is disabled, logs and returns early`() { - val sut = fixture.getSUT(isEnableSessionTracking = false, envelopeCache = fixture.cache) + fun `when session tracking is disabled, still moves previous session`() { + val sut = fixture.getSUT(isEnableSessionTracking = false) + + val currentSessionFile = EnvelopeCache.getCurrentSessionFile(fixture.options.cacheDirPath!!) + val previousSessionFile = EnvelopeCache.getPreviousSessionFile(fixture.options.cacheDirPath!!) + + currentSessionFile.createNewFile() + currentSessionFile.writeText("session content") sut.run() - verify(fixture.cache, never()).movePreviousSession(any(), any()) - verify(fixture.cache, never()).flushPreviousSession() + (fixture.options.envelopeDiskCache as EnvelopeCache).waitPreviousSessionFlush() + + assertFalse(currentSessionFile.exists()) + assertTrue(previousSessionFile.exists()) } @Test diff --git a/sentry/src/test/java/io/sentry/PreviousSessionFinalizerTest.kt b/sentry/src/test/java/io/sentry/PreviousSessionFinalizerTest.kt index 7a205d6d51..4b433ffb3e 100644 --- a/sentry/src/test/java/io/sentry/PreviousSessionFinalizerTest.kt +++ b/sentry/src/test/java/io/sentry/PreviousSessionFinalizerTest.kt @@ -210,27 +210,16 @@ class PreviousSessionFinalizerTest { } @Test - fun `if session tracking is disabled, does not wait for previous session flush`() { + fun `if session tracking is disabled, still finalizes previous session`() { val finalizer = fixture.getSut( tmpDir, - flushTimeoutMillis = 500L, + session = Session(null, null, null, "io.sentry.sample@1.0"), sessionTrackingEnabled = false, - shouldAwait = true, ) finalizer.run() - verify(fixture.logger, never()) - .log( - any(), - argThat { - startsWith( - "Timed out waiting to flush previous session to its own file in session finalizer." - ) - }, - any(), - ) - verify(fixture.scopes, never()).captureEnvelope(any()) + verify(fixture.scopes).captureEnvelope(any()) } @Test