Skip to content

Conversation

philprime
Copy link
Member

@philprime philprime commented Apr 22, 2025

📜 Description

On SDK startup we check if the app is already in foreground and manually trigger the logic of didBecomeActive.

💡 Motivation and Context

Currently the session tracker expects the didBecomeActive notification from the application life cycle after the SDK start. If we start the SDK after the app is opened, e.g. after fetching a remote config and initializing the SDK again, or if the user is asked for consent first, session tracking will not start until the app is in background for a while again.

Please see this comment for further details.

Closes #5069

💚 How did you test it?

  • Added unit tests
  • Used the start and close buttons in the sample apps

📝 Checklist

You have to check all boxes before merging:

  • 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.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

@philprime it would be great if we could first have a PR to only fix the problem that the SDK doesn't start a session when it's started after didBecomeActive to keep the change small. I think that's a standalone improvement that has nothing to do with SR.

@philprime
Copy link
Member Author

@philipphofmann I agree, it seems like somehow other changes leaked into the PR during rebasing

Copy link

codecov bot commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 90.40404% with 19 lines in your changes missing coverage. Please review.

Project coverage is 86.291%. Comparing base (5652830) to head (d3d2e50).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...tryTestUtils/TestNSNotificationCenterWrapper.swift 87.500% 19 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #5121       +/-   ##
=============================================
+ Coverage   86.179%   86.291%   +0.112%     
=============================================
  Files          399       399               
  Lines        34616     34819      +203     
  Branches     14972     15111      +139     
=============================================
+ Hits         29832     30046      +214     
+ Misses        4739      4733        -6     
+ Partials        45        40        -5     
Files with missing lines Coverage Δ
...rces/Sentry/SentryAutoSessionTrackingIntegration.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryDependencyContainer.m 88.262% <100.000%> (+0.282%) ⬆️
Sources/Sentry/SentryNSNotificationCenterWrapper.m 100.000% <100.000%> (ø)
Sources/Sentry/SentrySessionTracker.m 99.152% <100.000%> (+0.172%) ⬆️
Sources/Sentry/SentryUIApplication.m 58.602% <100.000%> (+0.678%) ⬆️
...tryTestUtils/TestNSNotificationCenterWrapper.swift 88.953% <87.500%> (-4.380%) ⬇️

... and 21 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5652830...d3d2e50. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

github-actions bot commented Apr 22, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1227.86 ms 1253.80 ms 25.95 ms
Size 23.75 KiB 848.09 KiB 824.34 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
c21082a 1215.02 ms 1243.19 ms 28.17 ms
02e1163 1199.86 ms 1211.78 ms 11.92 ms
ed49f0c 1215.94 ms 1245.63 ms 29.69 ms
742d4b6 1204.00 ms 1217.90 ms 13.90 ms
39f4c2a 1222.19 ms 1230.60 ms 8.42 ms
66922ca 1221.68 ms 1235.98 ms 14.30 ms
1bbcb9c 1214.25 ms 1230.04 ms 15.79 ms
1a4da1b 1222.14 ms 1239.50 ms 17.36 ms
f938d24 1223.26 ms 1242.12 ms 18.86 ms
3bf3c92 1236.94 ms 1253.00 ms 16.06 ms

App size

Revision Plain With Sentry Diff
c21082a 22.30 KiB 846.15 KiB 823.84 KiB
02e1163 21.58 KiB 418.82 KiB 397.24 KiB
ed49f0c 21.58 KiB 632.13 KiB 610.55 KiB
742d4b6 21.58 KiB 546.20 KiB 524.61 KiB
39f4c2a 23.75 KiB 846.88 KiB 823.13 KiB
66922ca 20.76 KiB 425.80 KiB 405.04 KiB
1bbcb9c 20.76 KiB 426.10 KiB 405.34 KiB
1a4da1b 21.58 KiB 418.33 KiB 396.75 KiB
f938d24 20.76 KiB 434.88 KiB 414.12 KiB
3bf3c92 21.58 KiB 706.06 KiB 684.48 KiB

Previous results on branch: philprime/issue-5069

Startup times

Revision Plain With Sentry Diff
927261d 1210.24 ms 1238.59 ms 28.35 ms
b5d1c3d 1231.00 ms 1255.47 ms 24.47 ms
bc06793 1231.04 ms 1247.98 ms 16.94 ms
4deddc5 1220.81 ms 1234.41 ms 13.60 ms
6996d49 1213.72 ms 1231.27 ms 17.55 ms
334d6f2 1202.65 ms 1232.21 ms 29.56 ms
5be643e 1217.51 ms 1246.15 ms 28.64 ms
7ba9cd4 1227.26 ms 1258.63 ms 31.37 ms
825200b 1200.16 ms 1227.76 ms 27.59 ms
9c7c623 1231.18 ms 1249.28 ms 18.09 ms

App size

Revision Plain With Sentry Diff
927261d 23.75 KiB 843.32 KiB 819.57 KiB
b5d1c3d 23.75 KiB 841.30 KiB 817.55 KiB
bc06793 23.75 KiB 847.75 KiB 824.00 KiB
4deddc5 23.76 KiB 822.08 KiB 798.32 KiB
6996d49 23.75 KiB 847.75 KiB 824.00 KiB
334d6f2 23.75 KiB 838.54 KiB 814.79 KiB
5be643e 23.76 KiB 820.06 KiB 796.30 KiB
7ba9cd4 23.75 KiB 847.86 KiB 824.12 KiB
825200b 23.75 KiB 847.90 KiB 824.15 KiB
9c7c623 23.76 KiB 822.00 KiB 798.24 KiB

@philprime philprime marked this pull request as ready for review April 23, 2025 15:27
@philprime philprime requested a review from armcknight as a code owner April 23, 2025 15:27
@philprime philprime self-assigned this Apr 23, 2025
@philprime philprime moved this to Needs Review in [DEPRECATED] Mobile SDKs Apr 23, 2025
Copy link
Member

@philipphofmann philipphofmann 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 tests failing. Either something is wrong with the test setup or the session logic is broken.

@philprime philprime marked this pull request as draft May 6, 2025 14:45
philprime and others added 2 commits June 13, 2025 15:12
…5343)

Co-authored-by: Philipp Hofmann <philipp.hofmann@sentry.io>
Co-authored-by: Andrew McKnight <andrew.mcknight@sentry.io>
Copy link
Member

@armcknight armcknight left a comment

Choose a reason for hiding this comment

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

Thanks for doing this work, some nice improvements in here. There are a couple test cases I wanted to understand better but these are the rest of the comments I have.

@philprime philprime requested a review from armcknight June 16, 2025 10:11
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. I found one potential major problem for the hybrid SDKs and another potential problem creating abnormal sessions. This is close to LGTM.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Almost LGTM. There are still two unresolved comments. Once we fix these, we should be goog do merge.

- Changed `stop` method to `stopWithGracefully:` in `SentrySessionTracker` to allow for graceful session termination.
- Updated related logic in `SentryAutoSessionTrackingIntegration` and tests to reflect the new method signature and behavior.
- Renamed internal flag from `wasDidBecomeActiveCalled` to `wasStartSessionCalled` for clarity.
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Almost LGTM. Just one open comment #5121 (comment).

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the multiple rounds of feedback.

@philprime philprime added the Waiting for: CI 🤖 Marks PR as ready-for-merge when CI passes. To be replaced with required checks. label Jun 23, 2025
@philprime philprime merged commit 476d5be into main Jun 23, 2025
150 of 154 checks passed
@philprime philprime deleted the philprime/issue-5069 branch June 23, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for: CI 🤖 Marks PR as ready-for-merge when CI passes. To be replaced with required checks.
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

Session Replay is not cleaned up correctly after calling Sentry.close
6 participants