Skip to content

Commit 90fd679

Browse files
authored
Fix properly reset application/content-provider timespans (#4244)
* Fix properly reset application/content-provider timespans * Update Changelog
1 parent f10c73c commit 90fd679

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- Fix Ensure app start type is set, even when ActivityLifecycleIntegration is not running ([#4216](https://github.com/getsentry/sentry-java/pull/4216))
8+
- Fix properly reset application/content-provider timespans for warm app starts ([#4244](https://github.com/getsentry/sentry-java/pull/4244))
89

910
## 7.22.0
1011

sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved
318318
appStartSpan.start();
319319
appStartSpan.setStartedAt(nowUptimeMs);
320320
CLASS_LOADED_UPTIME_MS = nowUptimeMs;
321+
contentProviderOnCreates.clear();
322+
applicationOnCreate.reset();
321323
} else {
322324
appStartType = savedInstanceState == null ? AppStartType.COLD : AppStartType.WARM;
323325
}

sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ class AppStartMetricsTest {
154154
val metrics = AppStartMetrics.getInstance()
155155
metrics.registerLifecycleCallbacks(mock<Application>())
156156

157+
metrics.contentProviderOnCreateTimeSpans.add(
158+
TimeSpan().apply {
159+
description = "ExampleContentProvider"
160+
setStartedAt(1)
161+
setStoppedAt(2)
162+
}
163+
)
164+
165+
metrics.applicationOnCreateTimeSpan.apply {
166+
setStartedAt(3)
167+
setStoppedAt(4)
168+
}
169+
157170
// when the looper runs
158171
Shadows.shadowOf(Looper.getMainLooper()).idle()
159172

@@ -173,6 +186,8 @@ class AppStartMetricsTest {
173186
assertTrue(metrics.shouldSendStartMeasurements())
174187
assertTrue(metrics.appStartTimeSpan.hasStarted())
175188
assertEquals(now, metrics.appStartTimeSpan.startUptimeMs)
189+
assertFalse(metrics.applicationOnCreateTimeSpan.hasStarted())
190+
assertTrue(metrics.contentProviderOnCreateTimeSpans.isEmpty())
176191
}
177192

178193
@Test

0 commit comments

Comments
 (0)