embrace-io / embrace-apple-sdk

Embrace's Swift SDK built on OpenTelemetry
https://embrace.io/docs/ios/
Apache License 2.0
117 stars 11 forks source link

Fixing background sessions logic in `SessionController` #72

Closed NachoEmbrace closed 2 months ago

NachoEmbrace commented 2 months ago

Even though we were parsing the background sessions remote config, we were never actually using it in the session logic. This PR adds the necessary validations into SessionController to drop background sessions if the config is disabled.

There's one special case that we have to deal with when the app is starting. In this scenario we can't know right away if the app is actually starting in the background or not. Due to this, the cold start session is always created even if the app is in the background and the config is disabled. Once the session ends it will be dropped unless the session state was updated to foreground.

We also updated the logic for "coldStart" sessions. Due to the changes in iOS 15 where apps can be pre-warmed by the OS, our calculations for the process start time are not accurate. For this reason we can't really know for sure how much time has passed since the process started and the first session is created. For this reason we will always flag the very first session as the "coldStart" session, regardless on how much time has passed since the process started.

Additionally, this PR adds 2 new resources: process start time and process pre warm.

github-actions[bot] commented 2 months ago

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

github-actions[bot] commented 2 months ago
Warnings
:warning: No CHANGELOG entry added.

Generated by :no_entry_sign: Danger Swift against b31d80d84abeec94ea091f03898b7d87751fcd9c

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 98.63636% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.82%. Comparing base (394bd68) to head (392bc06).

Files with missing lines Patch % Lines
...ources/EmbraceCore/Session/SessionController.swift 96.36% 2 Missing :warning:
...raceCoreTests/Session/SessionControllerTests.swift 99.30% 1 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72/graphs/tree.svg?width=650&height=150&src=pr&token=R3KMG2Ar52&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io)](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io) ```diff @@ Coverage Diff @@ ## main #72 +/- ## ========================================== + Coverage 91.76% 91.82% +0.06% ========================================== Files 403 404 +1 Lines 26152 26302 +150 ========================================== + Hits 23999 24153 +154 + Misses 2153 2149 -4 ``` | [Files with missing lines](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io) | Coverage Δ | | |---|---|---| | [Sources/EmbraceCore/Embrace.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FEmbrace.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9FbWJyYWNlLnN3aWZ0) | `81.16% <100.00%> (+0.37%)` | :arrow_up: | | [Sources/EmbraceCore/Internal/Embrace+Setup.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FInternal%2FEmbrace%2BSetup.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9JbnRlcm5hbC9FbWJyYWNlK1NldHVwLnN3aWZ0) | `84.88% <ø> (ø)` | | | [...n/ProcessUptime/DefaultProcessUptimeProvider.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FSession%2FProcessUptime%2FDefaultProcessUptimeProvider.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9TZXNzaW9uL1Byb2Nlc3NVcHRpbWUvRGVmYXVsdFByb2Nlc3NVcHRpbWVQcm92aWRlci5zd2lmdA==) | `100.00% <100.00%> (ø)` | | | [...ternal/Logs/EmbraceLogAttributesBuilderTests.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FInternal%2FLogs%2FEmbraceLogAttributesBuilderTests.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9JbnRlcm5hbC9Mb2dzL0VtYnJhY2VMb2dBdHRyaWJ1dGVzQnVpbGRlclRlc3RzLnN3aWZ0) | `100.00% <100.00%> (ø)` | | | [...ceCoreTests/Internal/Logs/LogControllerTests.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FInternal%2FLogs%2FLogControllerTests.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9JbnRlcm5hbC9Mb2dzL0xvZ0NvbnRyb2xsZXJUZXN0cy5zd2lmdA==) | `100.00% <ø> (ø)` | | | [...reTests/Public/Metadata/MetadataHandlerTests.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FPublic%2FMetadata%2FMetadataHandlerTests.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9QdWJsaWMvTWV0YWRhdGEvTWV0YWRhdGFIYW5kbGVyVGVzdHMuc3dpZnQ=) | `94.64% <100.00%> (ø)` | | | [...upport/TestDoubles/MockProcessUptimeProvider.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FTestSupport%2FTestDoubles%2FMockProcessUptimeProvider.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9UZXN0U3VwcG9ydC9UZXN0RG91Ymxlcy9Nb2NrUHJvY2Vzc1VwdGltZVByb3ZpZGVyLnN3aWZ0) | `100.00% <100.00%> (ø)` | | | [...estSupport/TestDoubles/MockSessionController.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FTestSupport%2FTestDoubles%2FMockSessionController.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9UZXN0U3VwcG9ydC9UZXN0RG91Ymxlcy9Nb2NrU2Vzc2lvbkNvbnRyb2xsZXIuc3dpZnQ=) | `100.00% <100.00%> (ø)` | | | [...raceCoreTests/Session/SessionControllerTests.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FSession%2FSessionControllerTests.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9TZXNzaW9uL1Nlc3Npb25Db250cm9sbGVyVGVzdHMuc3dpZnQ=) | `99.46% <99.30%> (-0.18%)` | :arrow_down: | | [...ources/EmbraceCore/Session/SessionController.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FSession%2FSessionController.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9TZXNzaW9uL1Nlc3Npb25Db250cm9sbGVyLnN3aWZ0) | `98.33% <96.36%> (-0.91%)` | :arrow_down: | ... and [3 files with indirect coverage changes](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/72/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io)