Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid stopping appStartProfiler after application creation #3630

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -4,6 +4,7 @@

### Fixes

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,14 @@ public void registerApplicationForegroundCheck(final @NotNull Application applic
// if no activity has ever been created, app was launched in background
if (onCreateTime == null) {
appLaunchedInForeground = false;

// we stop the app start profiler, as it's useless and likely to timeout
if (appStartProfiler != null && appStartProfiler.isRunning()) {
appStartProfiler.close();
appStartProfiler = null;
}
}
application.unregisterActivityLifecycleCallbacks(instance);
// we stop the app start profiler, as it's useless and likely to timeout
if (appStartProfiler != null && appStartProfiler.isRunning()) {
appStartProfiler.close();
appStartProfiler = null;
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ class AppStartMetricsTest {
verify(profiler).close()
}

@Test
fun `if activity is started, does not stop app start profiler if running`() {
val profiler = mock<ITransactionProfiler>()
whenever(profiler.isRunning).thenReturn(true)
AppStartMetrics.getInstance().appStartProfiler = profiler
AppStartMetrics.getInstance().onActivityCreated(mock(), mock())

AppStartMetrics.getInstance().registerApplicationForegroundCheck(mock())
// Job on main thread checks if activity was launched
Shadows.shadowOf(Looper.getMainLooper()).idle()

verify(profiler, never()).close()
}

@Test
fun `if app start span is longer than 1 minute, appStartTimeSpanWithFallback returns an empty span`() {
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan
Expand Down
Loading