-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3bd304
commit 3ec0698
Showing
13 changed files
with
368 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
sentry/src/main/java/io/sentry/SentryCrashLastRunState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.sentry; | ||
|
||
import io.sentry.cache.EnvelopeCache; | ||
import java.io.File; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.TestOnly; | ||
|
||
@ApiStatus.Internal | ||
public final class SentryCrashLastRunState { | ||
|
||
private static final SentryCrashLastRunState INSTANCE = new SentryCrashLastRunState(); | ||
|
||
private boolean readCrashedLastRun; | ||
private @Nullable Boolean crashedLastRun; | ||
|
||
private final @NotNull Object crashedLastRunLock = new Object(); | ||
|
||
private SentryCrashLastRunState() {} | ||
|
||
public static SentryCrashLastRunState getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
public @Nullable Boolean isCrashedLastRun( | ||
final @Nullable String cacheDirPath, final boolean deleteFile) { | ||
synchronized (crashedLastRunLock) { | ||
if (readCrashedLastRun) { | ||
return crashedLastRun; | ||
} | ||
|
||
if (cacheDirPath == null) { | ||
return null; | ||
} | ||
readCrashedLastRun = true; | ||
|
||
final File javaMarker = new File(cacheDirPath, EnvelopeCache.CRASH_MARKER_FILE); | ||
final File nativeMarker = new File(cacheDirPath, EnvelopeCache.NATIVE_CRASH_MARKER_FILE); | ||
boolean exists = false; | ||
try { | ||
if (javaMarker.exists()) { | ||
exists = true; | ||
|
||
javaMarker.delete(); | ||
} else if (nativeMarker.exists()) { | ||
exists = true; | ||
// only delete if release health is disabled, otherwise the session crashed by the native | ||
// side won't be marked as crashed correctly. | ||
if (deleteFile) { | ||
nativeMarker.delete(); | ||
} | ||
} | ||
} catch (Exception e) { | ||
// ignore | ||
} | ||
|
||
crashedLastRun = exists; | ||
} | ||
|
||
return crashedLastRun; | ||
} | ||
|
||
public void setCrashedLastRun(final boolean crashedLastRun) { | ||
synchronized (crashedLastRunLock) { | ||
if (!readCrashedLastRun) { | ||
this.crashedLastRun = crashedLastRun; | ||
// mark readCrashedLastRun as true since its being set directly | ||
readCrashedLastRun = true; | ||
} | ||
} | ||
} | ||
|
||
@TestOnly | ||
public void reset() { | ||
synchronized (crashedLastRunLock) { | ||
readCrashedLastRun = false; | ||
crashedLastRun = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import com.nhaarman.mockitokotlin2.times | |
import com.nhaarman.mockitokotlin2.verify | ||
import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import io.sentry.cache.EnvelopeCache | ||
import io.sentry.hints.SessionEndHint | ||
import io.sentry.hints.SessionStartHint | ||
import io.sentry.protocol.SentryId | ||
|
@@ -1187,9 +1188,9 @@ class HubTest { | |
|
||
@Test | ||
fun `when startTransaction and no tracing sampling is configured, event is not sampled`() { | ||
val hub = generateHub(Sentry.OptionsConfiguration { | ||
val hub = generateHub { | ||
it.tracesSampleRate = 0.0 | ||
}) | ||
} | ||
|
||
val transaction = hub.startTransaction("name", "op") | ||
assertFalse(transaction.isSampled!!) | ||
|
@@ -1221,10 +1222,10 @@ class HubTest { | |
|
||
@Test | ||
fun `when tracesSampleRate and tracesSampler are not set on SentryOptions, startTransaction returns NoOp`() { | ||
val hub = generateHub(Sentry.OptionsConfiguration { | ||
val hub = generateHub { | ||
it.tracesSampleRate = null | ||
it.tracesSampler = null | ||
}) | ||
} | ||
val transaction = hub.startTransaction(TransactionContext("name", "op", true)) | ||
assertTrue(transaction is NoOpTransaction) | ||
} | ||
|
@@ -1297,6 +1298,30 @@ class HubTest { | |
} | ||
// endregion | ||
|
||
@Test | ||
fun `isCrashedLastRun does not delete native marker if auto session is enabled`() { | ||
val nativeMarker = File(file.absolutePath, EnvelopeCache.NATIVE_CRASH_MARKER_FILE) | ||
nativeMarker.mkdirs() | ||
nativeMarker.createNewFile() | ||
val hub = generateHub() as Hub | ||
|
||
assertTrue(hub.isCrashedLastRun!!) | ||
assertTrue(nativeMarker.exists()) | ||
} | ||
|
||
@Test | ||
fun `isCrashedLastRun deletes the native marker if auto session is disabled`() { | ||
val nativeMarker = File(file.absolutePath, EnvelopeCache.NATIVE_CRASH_MARKER_FILE) | ||
nativeMarker.mkdirs() | ||
nativeMarker.createNewFile() | ||
val hub = generateHub { | ||
it.isEnableAutoSessionTracking = false | ||
} | ||
|
||
assertTrue(hub.isCrashedLastRun!!) | ||
assertFalse(nativeMarker.exists()) | ||
} | ||
|
||
private fun generateHub(optionsConfiguration: Sentry.OptionsConfiguration<SentryOptions>? = null): IHub { | ||
val options = SentryOptions().apply { | ||
dsn = "https://[email protected]/proj" | ||
|
Oops, something went wrong.