Skip to content

Commit 70d1da1

Browse files
authored
Avoid stopping appStartProfiler after application creation (#3630)
* AppStartMetrics stops appStartProfiler only if no activity ever started
1 parent 014dbef commit 70d1da1

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- Avoid stopping appStartProfiler after application creation ([#3630](https://github.com/getsentry/sentry-java/pull/3630))
8+
59
*Breaking changes*:
610

711
- `options.experimental.sessionReplay.errorSampleRate` was renamed to `options.experimental.sessionReplay.onErrorSampleRate` ([#3637](https://github.com/getsentry/sentry-java/pull/3637))

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,14 @@ private void checkCreateTimeOnMain(final @NotNull Application application) {
255255
// if no activity has ever been created, app was launched in background
256256
if (onCreateTime == null) {
257257
appLaunchedInForeground = false;
258+
259+
// we stop the app start profiler, as it's useless and likely to timeout
260+
if (appStartProfiler != null && appStartProfiler.isRunning()) {
261+
appStartProfiler.close();
262+
appStartProfiler = null;
263+
}
258264
}
259265
application.unregisterActivityLifecycleCallbacks(instance);
260-
// we stop the app start profiler, as it's useless and likely to timeout
261-
if (appStartProfiler != null && appStartProfiler.isRunning()) {
262-
appStartProfiler.close();
263-
appStartProfiler = null;
264-
}
265266
});
266267
}
267268

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)