Skip to content

Hook User Interaction integration into running Activity in case of deferred SDK init #4337

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

markushi
Copy link
Member

@markushi markushi commented Apr 15, 2025

📜 Description

Fixes #3746
Fixes #4356

💡 Motivation and Context

💚 How did you test it?

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@@ -6,6 +6,8 @@
import android.app.Application;
import android.os.Bundle;
import android.view.Window;
import androidx.lifecycle.Lifecycle;
Copy link
Member Author

Choose a reason for hiding this comment

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

Actual access to these optional deps is guarded by an if-check, I guess that should be good enough. Will do a manual test as well, just to be sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just did a test, works as expected 🚀

Copy link
Contributor

github-actions bot commented Apr 15, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 471.17 ms 523.91 ms 52.74 ms
Size 1.58 MiB 2.08 MiB 507.58 KiB

Previous results on branch: markushi/fix/ui-interactions-deferred-init

Startup times

Revision Plain With Sentry Diff
cefe7fd 445.92 ms 520.37 ms 74.45 ms
6d25951 476.36 ms 536.73 ms 60.37 ms
7d05d6e 409.78 ms 472.38 ms 62.59 ms
7c4015f 402.46 ms 454.08 ms 51.62 ms

App size

Revision Plain With Sentry Diff
cefe7fd 1.58 MiB 2.08 MiB 505.82 KiB
6d25951 1.58 MiB 2.08 MiB 505.87 KiB
7d05d6e 1.58 MiB 2.08 MiB 507.83 KiB
7c4015f 1.58 MiB 2.08 MiB 507.85 KiB

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

LGTM!

@stefanosiano
Copy link
Member

stefanosiano commented Apr 17, 2025

looks good, but now we always set the first Activity via AppStartMetrics, but we never clear it if CurrentActivityIntegration is not started, like with react/flutter.
It shouldn't be a problem, since we use the current activity for non-hybrid stuff anyway.
Your call on what to do:

  • call CurrentActivityHolder.getInstance().clearActivity() in the last Activity in AppStartMetrics
  • add a comment for the future in CurrentActivityHolder.getActivity() to be aware of the possible activity non-existence in hybrid sdk
  • completely replace the CurrentActivityIntegration with AppStartMetrics callback, so that it's always called in all environments

@@ -346,6 +347,13 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle saved

// the first activity determines the app start type
if (activeActivitiesCounter.incrementAndGet() == 1 && !firstDrawDone.get()) {

Copy link
Member

Choose a reason for hiding this comment

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

oh, I just realized - we only set the currentActivity for the first activity here right? So it won't be the "last known activity" but rather the first one, which is incorrect, right? E.g. if you launched 3 activities, and then initialized the SDK it would use the wrong one to hook user interactions. Unless I got the above if-check wrong 😅

Copy link
Member

Choose a reason for hiding this comment

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

yes, that's correct, it's a better rephrase of my comment 😅

@krystofwoldrich
Copy link
Member

@markushi Is it feasible to port to sentry-java@v7, this would help React Native with missing activity issue. (Sadly RN is still on v7.)

@krystofwoldrich
Copy link
Member

@stefanosiano but we never clear it if CurrentActivityIntegration is not started, like with react/flutter.

That's a good point, the CurrentActivityIntegration should be started for hybrids as well. Since we need it for slow and frozen frame, TTID, TTFD...

This RN PR fixes the CurrentActivityIntegration initialization in RN apps.

@markushi
Copy link
Member Author

@krystofwoldrich yes, we can backport it to v7!

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