From e4ca6a8305215ddae93a482937220e126b385c89 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 19 Nov 2026 17:58:47 +0100 Subject: [PATCH 1/2] fix(android): Time a warm relaunch within 1 minute from its own activity Since #4999, destroying the last activity marks the next launch as warm but keeps the process-start anchor unless the process is older than a minute. A quick relaunch was therefore timed from process start: standalone mode re-sent the cold interval as a second warm App Start, and the relaunched screen's TTID spanned the whole session. Refs JAVA-503 Co-Authored-By: Claude Opus 5.5 --- .../core/performance/AppStartMetrics.java | 7 +++++ .../core/performance/AppStartMetricsTest.kt | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java b/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java index 509296a846..4051ae6ebf 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java @@ -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); @@ -413,6 +416,7 @@ public void clear() { appLaunchedInForeground = null; isCallbackRegistered = false; shouldSendStartMeasurements = true; + isWarmRelaunchPending = false; firstDrawDone.set(false); activeActivitiesCounter.set(0); firstIdle = -1; @@ -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(); @@ -745,6 +751,7 @@ public void onActivityDestroyed(@NonNull Activity activity) { appStartType = AppStartType.WARM; appLaunchedInForeground = true; shouldSendStartMeasurements = true; + isWarmRelaunchPending = true; firstDrawDone.set(false); } } diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTest.kt index c4401d74c6..ab7b942b09 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTest.kt @@ -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 @@ -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() + 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(), 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() From 65fd006a73022d645950a98f752381f37aa12156 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 19 Nov 2026 17:59:16 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9472ec4027..353beefb7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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