Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Kotlin now sees `Attachment.getBytes()`, `Device.getArchs()`, `Spring.getActiveProfiles()` and `JsonSerializationUtils.bytesFrom(...)` as nullable, because `@Nullable` now annotates the returned array instead of its elements ([#6558](https://github.com/getsentry/sentry-java/pull/6558))
- Shake-to-report no longer leaks the first Activity that resumes after `Sentry.init` ([#6686](https://github.com/getsentry/sentry-java/pull/6686))
- Android app start: Reopening the app within a minute of process start is now reported as a warm start timed from the reopened screen, instead of reusing the cold start's timing. In standalone app start mode, this no longer sends the cold start a second time, as a warm start ([#6687](https://github.com/getsentry/sentry-java/pull/6687))

## 8.65.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public enum AppStartType {
private @Nullable TracesSamplingDecision appStartSamplingDecision = null;
private boolean isCallbackRegistered = false;
private volatile boolean shouldSendStartMeasurements = true;
// Set when the app moves to the background, so a relaunch in the same process is timed from its
// own activity rather than from the process start.
private volatile boolean isWarmRelaunchPending = false;
private final AtomicInteger activeActivitiesCounter = new AtomicInteger();
private final AtomicBoolean firstDrawDone = new AtomicBoolean(false);
private final AtomicBoolean headlessAppStartCheckPending = new AtomicBoolean(false);
Expand Down Expand Up @@ -413,6 +416,7 @@ public void clear() {
appLaunchedInForeground = null;
isCallbackRegistered = false;
shouldSendStartMeasurements = true;
isWarmRelaunchPending = false;
firstDrawDone.set(false);
activeActivitiesCounter.set(0);
firstIdle = -1;
Expand Down Expand Up @@ -677,8 +681,10 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved
// the extended vital measure from the activity while the eager app.start transaction stays
// anchored at process start.
if ((!isAppLaunchedInForeground()
|| isWarmRelaunchPending
|| durationSinceAppStartMillis > TimeUnit.MINUTES.toMillis(1))
&& !appStartExtension.isActive()) {
isWarmRelaunchPending = false;
appStartType = AppStartType.WARM;
shouldSendStartMeasurements = true;
appStartSpan.reset();
Expand Down Expand Up @@ -745,6 +751,7 @@ public void onActivityDestroyed(@NonNull Activity activity) {
appStartType = AppStartType.WARM;
appLaunchedInForeground = true;
shouldSendStartMeasurements = true;
isWarmRelaunchPending = true;
firstDrawDone.set(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import io.sentry.DateUtils
import io.sentry.IContinuousProfiler
import io.sentry.ITransaction
Expand Down Expand Up @@ -569,6 +570,32 @@ class AppStartMetricsTest {
assertTrue(appStartMetrics.shouldSendStartMeasurements(false))
}

@Test
fun `a warm relaunch within 1 minute of process start is timed from the new activity`() {
val metrics = AppStartMetrics.getInstance()
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
metrics.applicationOnCreateTimeSpan.setStartedAt(SystemClock.uptimeMillis())
metrics.applicationOnCreateTimeSpan.setStoppedAt(SystemClock.uptimeMillis() + 100)
metrics.contentProviderOnCreateTimeSpans.add(TimeSpan().apply { setStartedAt(1) })

val coldActivity = mock<Activity>()
metrics.onActivityCreated(coldActivity, null)
metrics.appStartTimeSpan.setStoppedAt(SystemClock.uptimeMillis() + 800)
metrics.onAppStartSpansSent()
metrics.onActivityDestroyed(coldActivity)

val relaunchUptimeMs = SystemClock.uptimeMillis() + TimeUnit.SECONDS.toMillis(25)
SystemClock.setCurrentTimeMillis(relaunchUptimeMs)
metrics.onActivityCreated(mock<Activity>(), null)

assertThat(metrics.appStartType).isEqualTo(AppStartMetrics.AppStartType.WARM)
assertThat(metrics.appStartTimeSpan.startUptimeMs).isEqualTo(relaunchUptimeMs)
assertThat(metrics.appStartTimeSpan.hasStopped()).isFalse()
assertThat(metrics.applicationOnCreateTimeSpan.hasStarted()).isFalse()
assertThat(metrics.contentProviderOnCreateTimeSpans).isEmpty()
assertThat(metrics.shouldSendStartMeasurements(false)).isTrue()
}

@Test
fun `provider sets both appstart and sdk init start + end times`() {
val metrics = AppStartMetrics.getInstance()
Expand Down
Loading