fix(session-tracker): add session start for SDK start after didBecomeActive
:scroll: Description
On SDK startup we check if the app is already in foreground and manually trigger the logic of didBecomeActive.
:bulb: 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
:green_heart: How did you test it?
- Added unit tests
- Used the
startandclosebuttons in the sample apps
:pencil: Checklist
You have to check all boxes before merging:
- [x] I added tests to verify the changes.
- [X] No new PII added or SDK only sends newly added PII if
sendDefaultPIIis enabled. - [X] I updated the docs if needed.
- [X] I updated the wizard if needed.
- [X] Review from the native team if needed.
- [X] No breaking change or entry added to the changelog.
- [X] No breaking change for hybrid SDKs or communicated to hybrid SDKs.
@philipphofmann I agree, it seems like somehow other changes leaked into the PR during rebasing
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 :warning: |
Additional details and impacted files
@@ 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%) |
:arrow_up: |
| Sources/Sentry/SentryNSNotificationCenterWrapper.m | 100.000% <100.000%> (ø) |
|
| Sources/Sentry/SentrySessionTracker.m | 99.152% <100.000%> (+0.172%) |
:arrow_up: |
| Sources/Sentry/SentryUIApplication.m | 58.602% <100.000%> (+0.678%) |
:arrow_up: |
| ...tryTestUtils/TestNSNotificationCenterWrapper.swift | 88.953% <87.500%> (-4.380%) |
:arrow_down: |
... 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 dataPowered by Codecov. Last update 5652830...d3d2e50. Read the comment docs.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Performance metrics :rocket:
| 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 |
|---|---|---|---|
| c21082ac0f5ec85e5c4979103d1878a666ee471c | 1215.02 ms | 1243.19 ms | 28.17 ms |
| 02e1163e424f7c819d266892cc54bd43e9635c30 | 1199.86 ms | 1211.78 ms | 11.92 ms |
| ed49f0c45e853d078735099abd82315b08ebb099 | 1215.94 ms | 1245.63 ms | 29.69 ms |
| 742d4b693cfd3cf2b7b1d62930d16daaf505d367 | 1204.00 ms | 1217.90 ms | 13.90 ms |
| 39f4c2aab9dc651cbd05886a0aa6e8dca875a156 | 1222.19 ms | 1230.60 ms | 8.42 ms |
| 66922caa6de29602cb803dadf1a5dcfcc2007ebd | 1221.68 ms | 1235.98 ms | 14.30 ms |
| 1bbcb9c080dd28de14e3f8583ce96130f7b9f865 | 1214.25 ms | 1230.04 ms | 15.79 ms |
| 1a4da1b80c362d90fcba0e7c5bc6a80d2289d391 | 1222.14 ms | 1239.50 ms | 17.36 ms |
| f938d24c96581fdda0c99af1bff59087d4b69f5c | 1223.26 ms | 1242.12 ms | 18.86 ms |
| 3bf3c92e6ef715d3461441b426604e22c2a74d60 | 1236.94 ms | 1253.00 ms | 16.06 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c21082ac0f5ec85e5c4979103d1878a666ee471c | 22.30 KiB | 846.15 KiB | 823.84 KiB |
| 02e1163e424f7c819d266892cc54bd43e9635c30 | 21.58 KiB | 418.82 KiB | 397.24 KiB |
| ed49f0c45e853d078735099abd82315b08ebb099 | 21.58 KiB | 632.13 KiB | 610.55 KiB |
| 742d4b693cfd3cf2b7b1d62930d16daaf505d367 | 21.58 KiB | 546.20 KiB | 524.61 KiB |
| 39f4c2aab9dc651cbd05886a0aa6e8dca875a156 | 23.75 KiB | 846.88 KiB | 823.13 KiB |
| 66922caa6de29602cb803dadf1a5dcfcc2007ebd | 20.76 KiB | 425.80 KiB | 405.04 KiB |
| 1bbcb9c080dd28de14e3f8583ce96130f7b9f865 | 20.76 KiB | 426.10 KiB | 405.34 KiB |
| 1a4da1b80c362d90fcba0e7c5bc6a80d2289d391 | 21.58 KiB | 418.33 KiB | 396.75 KiB |
| f938d24c96581fdda0c99af1bff59087d4b69f5c | 20.76 KiB | 434.88 KiB | 414.12 KiB |
| 3bf3c92e6ef715d3461441b426604e22c2a74d60 | 21.58 KiB | 706.06 KiB | 684.48 KiB |
Previous results on branch: philprime/issue-5069
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 927261d0a8b8fbd48de7d237eef1a828d35f9c92 | 1210.24 ms | 1238.59 ms | 28.35 ms |
| b5d1c3da4e5696e3f215bcb34bd8f4cc6591f38e | 1231.00 ms | 1255.47 ms | 24.47 ms |
| bc06793ac9c355061aa94fd0018a118a1eb576ac | 1231.04 ms | 1247.98 ms | 16.94 ms |
| 4deddc591f80e8d8e24e574261ff8ebf3db04603 | 1220.81 ms | 1234.41 ms | 13.60 ms |
| 6996d498f841e8805c7ea639b2047c874e2a0291 | 1213.72 ms | 1231.27 ms | 17.55 ms |
| 334d6f20972ac22a1d46f54f37a84108663d4711 | 1202.65 ms | 1232.21 ms | 29.56 ms |
| 5be643e4ec7be1924ead0d1d40b1cd59f905a30a | 1217.51 ms | 1246.15 ms | 28.64 ms |
| 7ba9cd4a616d71634e313e7a2d8f5157b55a73e1 | 1227.26 ms | 1258.63 ms | 31.37 ms |
| 825200ba1263ff20e82358f93383c4729c5976b5 | 1200.16 ms | 1227.76 ms | 27.59 ms |
| 9c7c623c4a033e50462991c1491395f1f789ab55 | 1231.18 ms | 1249.28 ms | 18.09 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 927261d0a8b8fbd48de7d237eef1a828d35f9c92 | 23.75 KiB | 843.32 KiB | 819.57 KiB |
| b5d1c3da4e5696e3f215bcb34bd8f4cc6591f38e | 23.75 KiB | 841.30 KiB | 817.55 KiB |
| bc06793ac9c355061aa94fd0018a118a1eb576ac | 23.75 KiB | 847.75 KiB | 824.00 KiB |
| 4deddc591f80e8d8e24e574261ff8ebf3db04603 | 23.76 KiB | 822.08 KiB | 798.32 KiB |
| 6996d498f841e8805c7ea639b2047c874e2a0291 | 23.75 KiB | 847.75 KiB | 824.00 KiB |
| 334d6f20972ac22a1d46f54f37a84108663d4711 | 23.75 KiB | 838.54 KiB | 814.79 KiB |
| 5be643e4ec7be1924ead0d1d40b1cd59f905a30a | 23.76 KiB | 820.06 KiB | 796.30 KiB |
| 7ba9cd4a616d71634e313e7a2d8f5157b55a73e1 | 23.75 KiB | 847.86 KiB | 824.12 KiB |
| 825200ba1263ff20e82358f93383c4729c5976b5 | 23.75 KiB | 847.90 KiB | 824.15 KiB |
| 9c7c623c4a033e50462991c1491395f1f789ab55 | 23.76 KiB | 822.00 KiB | 798.24 KiB |
After adding application state simulation to the unit tests, they fail with and without the changes of this PR. I'll will need to look into it with @philipphofmann to see if the tests are actually correct.
After a discussion the existing tests are valid, therefore indicating that my changes in this PR are not valid yet.
I manually confirmed that this actually fixes the issue with session replay by using the Close SDK and Start SDK buttons in the Sample App > Extras tab.