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

Fix Ensure app start type is set, even when ActivityLifecycleIntegration is not running #4216

Open
wants to merge 17 commits into
base: 7.x.x
Choose a base branch
from

Conversation

markushi
Copy link
Member

Fix Ensure app start type is set, even when ActivityLifecycleIntegration is not running or init is deferred.

Fixes getsentry/sentry-react-native#4598

Copy link
Contributor

github-actions bot commented Feb 28, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 404.83 ms 479.76 ms 74.93 ms
Size 1.70 MiB 2.36 MiB 671.82 KiB

Previous results on branch: markushi/fix/determine-app-start-type-via-content-provider

Startup times

Revision Plain With Sentry Diff
ab6e139 393.55 ms 447.32 ms 53.77 ms
904a89c 322.18 ms 410.63 ms 88.45 ms
45c7ce0 358.77 ms 391.41 ms 32.64 ms
71b4c74 374.74 ms 407.65 ms 32.91 ms
48f18b6 373.96 ms 402.54 ms 28.58 ms
43531dd 428.61 ms 465.58 ms 36.97 ms

App size

Revision Plain With Sentry Diff
ab6e139 1.70 MiB 2.36 MiB 671.71 KiB
904a89c 1.70 MiB 2.36 MiB 671.74 KiB
45c7ce0 1.70 MiB 2.36 MiB 672.38 KiB
71b4c74 1.70 MiB 2.36 MiB 671.82 KiB
48f18b6 1.70 MiB 2.36 MiB 672.40 KiB
43531dd 1.70 MiB 2.36 MiB 672.39 KiB

Comment on lines 357 to 363

/**
* @param hasBundle true if the activity onCreate had a non-null bundle
* @param lastKnownStart in case the app start is too long, resets the app start timestamp to this
* value
*/
public void updateAppStartType(final boolean hasBundle, final long lastKnownStart) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* @param hasBundle true if the activity onCreate had a non-null bundle
* @param lastKnownStart in case the app start is too long, resets the app start timestamp to this
* value
*/
public void updateAppStartType(final boolean hasBundle, final long lastKnownStart) {
/**
* @param hasBundle true if the activity onCreate had a non-null bundle
* @param startUptimeMillis in case the app start is too long, resets the app start timestamp to this
* value, retrieved via System.uptimeMillis()
*/
public void updateAppStartType(final boolean hasBundle, final long startUptimeMillis) {

Just make it clear we want a time from System.uptimeMillis()

Copy link
Member

@stefanosiano stefanosiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!
Can you also add the activity configuration check in the ActivityLifecycleIntegration, so that rotating the device doesn't count as warm start?

@markushi markushi requested a review from stefanosiano March 3, 2025 20:46
markushi and others added 2 commits March 4, 2025 15:25
* changed RateLimiterTest `close cancels the timer` to use reflection
Copy link
Member

@stefanosiano stefanosiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a few things to adjust

app.unregisterActivityLifecycleCallbacks(activityCallback);
}
}
appStartMetrics.registerLifecycleCallbacks(app);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a behavioural change, as we were not doing it on API < 24, while now we would. I'd keep the previous check that returns early

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's on purpose - otherwise we would need to duplicate half of the logic within AppStartMetrics again, app start type, foreground importance, etc..

markushi and others added 7 commits March 4, 2025 19:52
…ityLifecycleIntegration.java

Co-authored-by: Stefano <stefano.siano@sentry.io>
…der' of github.com:getsentry/sentry-java into markushi/fix/determine-app-start-type-via-content-provider
…der' of github.com:getsentry/sentry-java into markushi/fix/determine-app-start-type-via-content-provider
@markushi markushi requested a review from stefanosiano March 6, 2025 05:58
@krystofwoldrich
Copy link
Member

@stefanosiano @markushi, let me and @denrase know if we should try this again with RN and Flutter before merging since there have been many changes since the initial draft.

@denrase
Copy link
Collaborator

denrase commented Mar 6, 2025

@krystofwoldrich I'll test again and report back.

@denrase
Copy link
Collaborator

denrase commented Mar 6, 2025

@markushi @krystofwoldrich So i was not able to verify this, now we bail out earlier, as the data suggests the app is not started in foreground. Also could not see in the debugger that the relevant code-paths in SentryPerformanceProvider.java were called.

Bildschirmfoto 2025-03-06 um 11 56 24

@stefanosiano
Copy link
Member

@denrase @krystofwoldrich can you try now?

@denrase
Copy link
Collaborator

denrase commented Mar 6, 2025

@stefanosiano Worked, now cold start is even detected when i'm in debug mode. 👍

Bildschirmfoto 2025-03-06 um 14 46 12

@krystofwoldrich
Copy link
Member

I'm testing it with RN right now.

@krystofwoldrich
Copy link
Member

Cold app start is correctly detected. But I struggle to get warm app start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants