Skip to content

Commit

Permalink
Filter out app starts with more than 60s (#2127)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Jun 24, 2022
1 parent c214795 commit 4a0e412
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Filter out app starts with more than 60s ([#2127](https://github.com/getsentry/sentry-java/pull/2127))

## 6.1.3

### Fixes
Expand Down
Expand Up @@ -13,6 +13,9 @@ public final class AppStartState {

private static @NotNull AppStartState instance = new AppStartState();

/** We filter out App starts more than 60s */
private static final int MAX_APP_START_MILLIS = 60000;

private @Nullable Long appStartMillis;

private @Nullable Long appStartEndMillis;
Expand Down Expand Up @@ -48,7 +51,21 @@ public synchronized Long getAppStartInterval() {
if (appStartMillis == null || appStartEndMillis == null || coldStart == null) {
return null;
}
return appStartEndMillis - appStartMillis;
final long appStart = appStartEndMillis - appStartMillis;

// We filter out app start more than 60s.
// This could be due to many different reasons.
// If you do the manual init and init the SDK too late and it does not compute the app start end
// in the very first Activity.
// If the process starts but the App isn't in the foreground.
// If the system forked the zygote earlier to accelerate the app start.
// And some unknown reasons that could not be reproduced.
// We've seen app starts with hours, days and even months.
if (appStart >= MAX_APP_START_MILLIS) {
return null;
}

return appStart;
}

public @Nullable Boolean isColdStart() {
Expand Down
Expand Up @@ -20,7 +20,8 @@
/**
* SentryPerformanceProvider is responsible for collecting data (eg appStart) as early as possible
* as ContentProvider is the only reliable hook for libraries that works across all the supported
* SDK versions. When minSDK is >= 24, we could use Process.getStartUptimeMillis()
* SDK versions. When minSDK is >= 24, we could use Process.getStartUptimeMillis() We could also use
* AppComponentFactory but it depends on androidx.core.app.AppComponentFactory
*/
@ApiStatus.Internal
public final class SentryPerformanceProvider extends ContentProvider
Expand Down
Expand Up @@ -77,4 +77,16 @@ class AppStartStateTest {

assertEquals(400, sut.appStartInterval)
}

@Test
fun `getAppStartInterval returns null if more than 60s`() {
val sut = AppStartState.getInstance()

val date = Date()
sut.setAppStartTime(100, date)
sut.setAppStartEnd(60100)
sut.setColdStart(true)

assertNull(sut.appStartInterval)
}
}

0 comments on commit 4a0e412

Please sign in to comment.