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 @@ -12,6 +12,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))
- Android app start: On Android 10+, a warm start now begins when the screen starts being created, matching its `activity.load` span ([#6719](https://github.com/getsentry/sentry-java/pull/6719))

## 8.65.0

Expand Down
1 change: 1 addition & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ public final class io/sentry/android/core/performance/AppStartMetrics : io/sentr
public fun onActivityCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityDestroyed (Landroid/app/Activity;)V
public fun onActivityPaused (Landroid/app/Activity;)V
public fun onActivityPreCreated (Landroid/app/Activity;Landroid/os/Bundle;)V
public fun onActivityResumed (Landroid/app/Activity;)V
public fun onActivityStarted (Landroid/app/Activity;)V
public fun onActivityStopped (Landroid/app/Activity;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public enum AppStartType {
// own activity rather than from the process start.
private volatile boolean isWarmRelaunchPending = false;
private final AtomicInteger activeActivitiesCounter = new AtomicInteger();
// Main thread only. Set in onActivityPreCreated, consumed by the onActivityCreated that follows.
private long activityPreCreatedUptimeMs = -1;
private final AtomicBoolean firstDrawDone = new AtomicBoolean(false);
private final AtomicBoolean headlessAppStartCheckPending = new AtomicBoolean(false);
private final AtomicBoolean headlessAppStartListenerInvoked = new AtomicBoolean(false);
Expand Down Expand Up @@ -419,6 +421,7 @@ public void clear() {
isWarmRelaunchPending = false;
firstDrawDone.set(false);
activeActivitiesCounter.set(0);
activityPreCreatedUptimeMs = -1;
firstIdle = -1;
headlessAppStartCheckPending.set(false);
headlessAppStartListenerInvoked.set(false);
Expand Down Expand Up @@ -664,9 +667,20 @@ private void stopHeadlessAppStartAt(final long stopUptimeMs) {
}
}

@Override
public void onActivityPreCreated(
@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
// ActivityLifecycleIntegration starts the activity.load span here, so a warm app start must not
// start any later than that. Classification stays in onActivityCreated, which also runs when
// the SDK is initialized inside Activity.onCreate, after this callback was dispatched.
activityPreCreatedUptimeMs = SystemClock.uptimeMillis();
}

@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
final long activityCreatedUptimeMillis = SystemClock.uptimeMillis();
final long activityCreatedUptimeMillis =
activityPreCreatedUptimeMs != -1 ? activityPreCreatedUptimeMs : SystemClock.uptimeMillis();
activityPreCreatedUptimeMs = -1;
CurrentActivityHolder.getInstance().setActivity(activity);

// the first activity determines the app start type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,44 @@ class AppStartMetricsTest {
assertThat(metrics.shouldSendStartMeasurements(false)).isTrue()
}

@Test
@Config(sdk = [Build.VERSION_CODES.Q])
fun `on API 29+ a warm start is timed from onActivityPreCreated`() {
val metrics = AppStartMetrics.getInstance()
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
val coldActivity = mock<Activity>()
metrics.onActivityPreCreated(coldActivity, null)
metrics.onActivityCreated(coldActivity, null)
metrics.onActivityDestroyed(coldActivity)

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

assertThat(metrics.appStartType).isEqualTo(AppStartMetrics.AppStartType.WARM)
assertThat(metrics.appStartTimeSpan.startUptimeMs).isEqualTo(preCreatedUptimeMs)
}

@Test
@Config(sdk = [Build.VERSION_CODES.Q])
fun `on API 29+ a warm start is still detected when onActivityPreCreated was missed`() {
val metrics = AppStartMetrics.getInstance()
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
val coldActivity = mock<Activity>()
metrics.onActivityCreated(coldActivity, null)
metrics.onActivityDestroyed(coldActivity)

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

assertThat(metrics.appStartType).isEqualTo(AppStartMetrics.AppStartType.WARM)
assertThat(metrics.appStartTimeSpan.startUptimeMs).isEqualTo(createdUptimeMs)
}

@Test
fun `provider sets both appstart and sdk init start + end times`() {
val metrics = AppStartMetrics.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ class AppStartMetricsTestApi35 {
// User opens the app 20s later (under the 1-minute warm threshold).
val activityCreatedUptimeMs = 20_000L
SystemClock.setCurrentTimeMillis(activityCreatedUptimeMs)
metrics.onActivityCreated(mock<Activity>(), null)
val activity = mock<Activity>()
metrics.onActivityPreCreated(activity, null)
metrics.onActivityCreated(activity, null)

// Re-classified as a warm start re-anchored at activity creation.
assertEquals(AppStartMetrics.AppStartType.WARM, metrics.appStartType)
Expand Down
Loading