Skip to content

fix(android): Init with ApplicationContext if available #4780

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

Merged
merged 6 commits into from
Apr 30, 2025

Conversation

krystofwoldrich
Copy link
Contributor

@krystofwoldrich krystofwoldrich commented Apr 25, 2025

📢 Type of change

  • Bugfix
  • Enhancement

📜 Description

This PR passes applicationContext to the sentry-android initialization function.

This PR is need for improving the current activity tracking from getsentry/sentry-java#4337.

Passing applicationContext will cause the CurrentActivityIntegration to be added, which ensures that if activity changes, the global holder hast the correct reference.

💚 How did you test it?

sample app, unit tests

📝 Checklist

  • I added tests to verify 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.
  • All tests passing
  • No breaking changes

🔮 Next steps

Copy link
Contributor

github-actions bot commented Apr 25, 2025

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 443.55 ms 458.64 ms 15.09 ms
Size 17.75 MiB 20.13 MiB 2.38 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
b7e707e 422.32 ms 412.10 ms -10.22 ms
3853f43 329.68 ms 346.32 ms 16.64 ms
d16beca 448.87 ms 447.20 ms -1.67 ms
77680ec 482.22 ms 475.07 ms -7.16 ms
31e279d 444.07 ms 443.65 ms -0.41 ms
8900e1a+dirty 430.68 ms 456.13 ms 25.44 ms
62a750b 395.96 ms 423.36 ms 27.41 ms
22bcd92 441.47 ms 428.18 ms -13.29 ms
d43a46b 454.22 ms 477.79 ms 23.57 ms
a15d370 431.43 ms 440.25 ms 8.82 ms

App size

Revision Plain With Sentry Diff
b7e707e 17.75 MiB 20.13 MiB 2.38 MiB
3853f43 17.73 MiB 19.81 MiB 2.08 MiB
d16beca 17.74 MiB 20.10 MiB 2.36 MiB
77680ec 17.74 MiB 20.08 MiB 2.34 MiB
31e279d 17.75 MiB 20.13 MiB 2.38 MiB
8900e1a+dirty 17.73 MiB 19.75 MiB 2.01 MiB
62a750b 17.73 MiB 19.93 MiB 2.20 MiB
22bcd92 17.75 MiB 20.12 MiB 2.37 MiB
d43a46b 17.73 MiB 20.06 MiB 2.33 MiB
a15d370 17.75 MiB 20.13 MiB 2.38 MiB

Previous results on branch: kw-fix-andoroid-context

Startup times

Revision Plain With Sentry Diff
703667e 443.04 ms 431.59 ms -11.45 ms

App size

Revision Plain With Sentry Diff
703667e 17.75 MiB 20.13 MiB 2.38 MiB

Copy link
Contributor

github-actions bot commented Apr 25, 2025

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1222.89 ms 1230.45 ms 7.56 ms
Size 2.63 MiB 3.78 MiB 1.15 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
8e80789+dirty 1228.04 ms 1237.20 ms 9.16 ms
eb1e19f+dirty 1209.56 ms 1214.94 ms 5.38 ms
950b04f+dirty 1223.18 ms 1222.48 ms -0.71 ms
73fc872+dirty 1236.16 ms 1237.15 ms 0.99 ms
e2aa97e+dirty 1227.40 ms 1233.65 ms 6.26 ms
48ad514+dirty 1235.90 ms 1238.20 ms 2.31 ms
a989877+dirty 1228.56 ms 1227.71 ms -0.85 ms
5e5c392+dirty 1231.96 ms 1228.74 ms -3.21 ms
8c88ac7+dirty 1205.13 ms 1218.87 ms 13.74 ms
9c48b2c+dirty 1246.96 ms 1255.73 ms 8.77 ms

App size

Revision Plain With Sentry Diff
8e80789+dirty 2.36 MiB 3.10 MiB 759.43 KiB
eb1e19f+dirty 2.36 MiB 3.08 MiB 737.21 KiB
950b04f+dirty 2.63 MiB 3.78 MiB 1.14 MiB
73fc872+dirty 2.63 MiB 3.76 MiB 1.13 MiB
e2aa97e+dirty 2.63 MiB 3.75 MiB 1.12 MiB
48ad514+dirty 2.63 MiB 3.75 MiB 1.12 MiB
a989877+dirty 2.36 MiB 3.10 MiB 752.40 KiB
5e5c392+dirty 2.63 MiB 3.75 MiB 1.12 MiB
8c88ac7+dirty 2.36 MiB 3.10 MiB 752.63 KiB
9c48b2c+dirty 2.36 MiB 2.85 MiB 495.77 KiB

Previous results on branch: kw-fix-andoroid-context

Startup times

Revision Plain With Sentry Diff
703667e+dirty 1224.57 ms 1220.63 ms -3.94 ms

App size

Revision Plain With Sentry Diff
703667e+dirty 2.63 MiB 3.78 MiB 1.15 MiB

Copy link
Contributor

github-actions bot commented Apr 25, 2025

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 400.87 ms 388.47 ms -12.40 ms
Size 7.15 MiB 8.40 MiB 1.25 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
13f280b+dirty 376.13 ms 406.41 ms 30.28 ms
31e279d+dirty 458.49 ms 467.69 ms 9.20 ms
1c65324+dirty 381.10 ms 427.26 ms 46.16 ms
eb1e19f+dirty 391.37 ms 418.27 ms 26.90 ms
a15d370+dirty 376.25 ms 388.17 ms 11.92 ms
ac41368+dirty 395.91 ms 451.17 ms 55.26 ms
255d28b+dirty 389.76 ms 382.73 ms -7.03 ms
87dd218+dirty 449.30 ms 459.66 ms 10.36 ms
e2b64fe+dirty 258.82 ms 304.26 ms 45.44 ms
e4ac943+dirty 384.67 ms 383.37 ms -1.30 ms

App size

Revision Plain With Sentry Diff
13f280b+dirty 7.15 MiB 8.35 MiB 1.20 MiB
31e279d+dirty 7.15 MiB 8.40 MiB 1.25 MiB
1c65324+dirty 7.15 MiB 8.22 MiB 1.07 MiB
eb1e19f+dirty 7.15 MiB 8.35 MiB 1.20 MiB
a15d370+dirty 7.15 MiB 8.40 MiB 1.25 MiB
ac41368+dirty 7.15 MiB 8.39 MiB 1.24 MiB
255d28b+dirty 7.15 MiB 8.39 MiB 1.23 MiB
87dd218+dirty 7.15 MiB 8.39 MiB 1.23 MiB
e2b64fe+dirty 7.15 MiB 8.07 MiB 947.16 KiB
e4ac943+dirty 7.15 MiB 8.40 MiB 1.25 MiB

Previous results on branch: kw-fix-andoroid-context

Startup times

Revision Plain With Sentry Diff
703667e+dirty 413.84 ms 407.36 ms -6.48 ms

App size

Revision Plain With Sentry Diff
703667e+dirty 7.15 MiB 8.40 MiB 1.25 MiB

Copy link
Contributor

github-actions bot commented Apr 25, 2025

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1227.59 ms 1228.33 ms 0.73 ms
Size 3.19 MiB 4.35 MiB 1.16 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
8e80789+dirty 1235.66 ms 1223.78 ms -11.88 ms
eb1e19f+dirty 1229.91 ms 1231.63 ms 1.71 ms
950b04f+dirty 1220.28 ms 1218.07 ms -2.21 ms
73fc872+dirty 1235.27 ms 1228.18 ms -7.08 ms
e2aa97e+dirty 1220.17 ms 1219.81 ms -0.36 ms
48ad514+dirty 1230.53 ms 1233.76 ms 3.22 ms
a989877+dirty 1222.90 ms 1219.89 ms -3.00 ms
5e5c392+dirty 1224.72 ms 1229.52 ms 4.80 ms
8c88ac7+dirty 1240.66 ms 1247.42 ms 6.76 ms
9c48b2c+dirty 1253.39 ms 1256.30 ms 2.91 ms

App size

Revision Plain With Sentry Diff
8e80789+dirty 2.92 MiB 3.67 MiB 772.00 KiB
eb1e19f+dirty 2.92 MiB 3.64 MiB 742.82 KiB
950b04f+dirty 3.19 MiB 4.34 MiB 1.16 MiB
73fc872+dirty 3.19 MiB 4.33 MiB 1.14 MiB
e2aa97e+dirty 3.19 MiB 4.32 MiB 1.13 MiB
48ad514+dirty 3.19 MiB 4.32 MiB 1.13 MiB
a989877+dirty 2.92 MiB 3.66 MiB 757.66 KiB
5e5c392+dirty 3.19 MiB 4.32 MiB 1.13 MiB
8c88ac7+dirty 2.92 MiB 3.66 MiB 757.12 KiB
9c48b2c+dirty 2.92 MiB 3.41 MiB 499.97 KiB

Previous results on branch: kw-fix-andoroid-context

Startup times

Revision Plain With Sentry Diff
703667e+dirty 1235.29 ms 1229.43 ms -5.86 ms

App size

Revision Plain With Sentry Diff
703667e+dirty 3.19 MiB 4.35 MiB 1.16 MiB

@krystofwoldrich krystofwoldrich marked this pull request as ready for review April 28, 2025 15:34
@lucas-zimerman
Copy link
Collaborator

Does it make sense to add the blocking label if this PR depends on the mentioned Java PR?

Copy link
Collaborator

@antonis antonis left a comment

Choose a reason for hiding this comment

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

The changes on this PR and the unit tests LGTM 🚀

@krystofwoldrich
Copy link
Contributor Author

The Android init expects to receive Application instance, regardless the deferred init, so I would go ahead merging this.

@krystofwoldrich krystofwoldrich merged commit a2f777c into main Apr 30, 2025
62 of 64 checks passed
@krystofwoldrich krystofwoldrich deleted the kw-fix-andoroid-context branch April 30, 2025 08:58
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.

3 participants