Skip to content

Commit 0fe51fc

Browse files
authored
Merge 7016a16 into d4b1f82
2 parents d4b1f82 + 7016a16 commit 0fe51fc

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- Avoid stopping appStartProfiler after application creation ([#3630](https://github.com/getsentry/sentry-java/pull/3630))
78
- Avoid ArrayIndexOutOfBoundsException on Android cpu data collection ([#3598](https://github.com/getsentry/sentry-java/pull/3598))
89
- Fix lazy select queries instrumentation ([#3604](https://github.com/getsentry/sentry-java/pull/3604))
910

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,14 @@ public void registerApplicationForegroundCheck(final @NotNull Application applic
247247
// if no activity has ever been created, app was launched in background
248248
if (onCreateTime == null) {
249249
appLaunchedInForeground = false;
250+
251+
// we stop the app start profiler, as it's useless and likely to timeout
252+
if (appStartProfiler != null && appStartProfiler.isRunning()) {
253+
appStartProfiler.close();
254+
appStartProfiler = null;
255+
}
250256
}
251257
application.unregisterActivityLifecycleCallbacks(instance);
252-
// we stop the app start profiler, as it's useless and likely to timeout
253-
if (appStartProfiler != null && appStartProfiler.isRunning()) {
254-
appStartProfiler.close();
255-
appStartProfiler = null;
256-
}
257258
});
258259
}
259260

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

+14
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ class AppStartMetricsTest {
196196
verify(profiler).close()
197197
}
198198

199+
@Test
200+
fun `if activity is started, does not stop app start profiler if running`() {
201+
val profiler = mock<ITransactionProfiler>()
202+
whenever(profiler.isRunning).thenReturn(true)
203+
AppStartMetrics.getInstance().appStartProfiler = profiler
204+
AppStartMetrics.getInstance().onActivityCreated(mock(), mock())
205+
206+
AppStartMetrics.getInstance().registerApplicationForegroundCheck(mock())
207+
// Job on main thread checks if activity was launched
208+
Shadows.shadowOf(Looper.getMainLooper()).idle()
209+
210+
verify(profiler, never()).close()
211+
}
212+
199213
@Test
200214
fun `if app start span is longer than 1 minute, appStartTimeSpanWithFallback returns an empty span`() {
201215
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan

0 commit comments

Comments
 (0)