Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Finalize previous session even when auto session tracking is disabled ([#5154](https://github.com/getsentry/sentry-java/pull/5154))

## 8.34.0

### Features
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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.");
Expand Down
8 changes: 0 additions & 8 deletions sentry/src/main/java/io/sentry/MovePreviousSession.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.sentry;

import static io.sentry.SentryLevel.DEBUG;
import static io.sentry.SentryLevel.INFO;

import io.sentry.cache.EnvelopeCache;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
16 changes: 12 additions & 4 deletions sentry/src/test/java/io/sentry/MovePreviousSessionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 3 additions & 14 deletions sentry/src/test/java/io/sentry/PreviousSessionFinalizerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any>(),
)
verify(fixture.scopes, never()).captureEnvelope(any())
verify(fixture.scopes).captureEnvelope(any())
}

@Test
Expand Down
Loading