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

Improving instrumentation around `UIViewController` #126

Closed NachoEmbrace closed 2 days ago

NachoEmbrace commented 1 week ago

This is a refactor on ViewCaptureService.

It still retains the old functionality: It creates emb-screen-view spans when viewDidAppear is called on a UIViewController. These spans are ended when viewDidDisappear is called. This feature can be enabled/disabled through ViewCaptureService.Options.instrumentVisibility.

Added a new feature to automatically instrument the time-to-render on UIViewControllers. This will create a parent span starting from viewDidLoad and ending on viewDidAppear. The parent span will contain child spans for each step of the loading process (viewDidLoad. viewWillAppear and viewDidAppear). The user can enable/disable this through ViewCaptureService.Options.instrumetTimeToRender.

If the UIViewController implements the InteractableViewController protocol, the service will create the time-to-interactive span instead. This is a parent span starting from viewDidLoad and ending when the view is deemed as ready to be interacted or the UIViewController disappears. The implementers must call InteractableViewController.onInteractionReady() to flag the view as ready. The parent span will contain child spans for each step of the loading process (viewDidLoad. viewWillAppear and viewDidAppear), and an extra ui-ready span that starts at the end of viewDidAppear and ends when the view is ready for interaction.

Furthermore, if the UIViewController implements the InstrumentableViewController protocol, it can use the buildChildSpan and recordCompletedChildSpan methods to add custom child spans to the time-to-render/time-to-interactive parent spans.

github-actions[bot] commented 1 week ago

Dependency Review

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

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

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

Generated by :no_entry_sign: Danger Swift against 0bba885f80a931273114de15c484e343c084cfb5

codecov[bot] commented 4 days ago

Codecov Report

Attention: Patch coverage is 92.48945% with 89 lines in your changes missing coverage. Please review.

Project coverage is 91.92%. Comparing base (584ee27) to head (b037a0d). Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...UX/View/CaptureServicesUIViewControllerTests.swift 86.07% 22 Missing :warning:
.../View/Protocols/InstrumentableViewController.swift 0.00% 19 Missing :warning:
...Core/Capture/UX/View/ViewCaptureServiceError.swift 38.46% 16 Missing :warning:
...Core/Capture/UX/View/UIViewControllerHandler.swift 97.06% 9 Missing :warning:
...braceCore/Capture/UX/View/ViewCaptureService.swift 90.62% 9 Missing :warning:
...w/Protocols/CaptureServices+UIViewController.swift 92.53% 5 Missing :warning:
...Capture/UX/View/UIViewControllerHandlerTests.swift 98.93% 4 Missing :warning:
...UX/View/Protocols/InteractableViewController.swift 0.00% 3 Missing :warning:
...ore/Capture/UX/View/UIViewController+Embrace.swift 93.75% 2 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126/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/126?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 #126 +/- ## ========================================== - Coverage 91.95% 91.92% -0.03% ========================================== Files 410 418 +8 Lines 26603 27563 +960 ========================================== + Hits 24462 25337 +875 - Misses 2141 2226 +85 ``` | [Files with missing lines](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?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/Capture/CaptureServices.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FCapture%2FCaptureServices.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9DYXB0dXJlL0NhcHR1cmVTZXJ2aWNlcy5zd2lmdA==) | `79.34% <100.00%> (+0.93%)` | :arrow_up: | | [...tions/PushNotificationCaptureService+Options.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FCapture%2FPushNotifications%2FPushNotificationCaptureService%2BOptions.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9DYXB0dXJlL1B1c2hOb3RpZmljYXRpb25zL1B1c2hOb3RpZmljYXRpb25DYXB0dXJlU2VydmljZStPcHRpb25zLnN3aWZ0) | `50.00% <ø> (ø)` | | | [...Protocols/EmbraceViewControllerCustomization.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FCapture%2FUX%2FView%2FProtocols%2FEmbraceViewControllerCustomization.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9DYXB0dXJlL1VYL1ZpZXcvUHJvdG9jb2xzL0VtYnJhY2VWaWV3Q29udHJvbGxlckN1c3RvbWl6YXRpb24uc3dpZnQ=) | `50.00% <100.00%> (ø)` | | | [...e/Capture/UX/View/ViewCaptureService+Options.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FCapture%2FUX%2FView%2FViewCaptureService%2BOptions.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9DYXB0dXJlL1VYL1ZpZXcvVmlld0NhcHR1cmVTZXJ2aWNlK09wdGlvbnMuc3dpZnQ=) | `100.00% <100.00%> (ø)` | | | [Sources/EmbraceCore/Public/Embrace+OTel.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FPublic%2FEmbrace%2BOTel.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9QdWJsaWMvRW1icmFjZStPVGVsLnN3aWZ0) | `70.75% <ø> (ø)` | | | [.../Capture/UX/View/MockUIViewControllerHandler.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FCapture%2FUX%2FView%2FMockUIViewControllerHandler.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9DYXB0dXJlL1VYL1ZpZXcvTW9ja1VJVmlld0NvbnRyb2xsZXJIYW5kbGVyLnN3aWZ0) | `100.00% <100.00%> (ø)` | | | [...X/View/MockUIViewControllerHandlerDataSource.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FCapture%2FUX%2FView%2FMockUIViewControllerHandlerDataSource.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9DYXB0dXJlL1VYL1ZpZXcvTW9ja1VJVmlld0NvbnRyb2xsZXJIYW5kbGVyRGF0YVNvdXJjZS5zd2lmdA==) | `100.00% <100.00%> (ø)` | | | [...ests/Capture/UX/View/ViewCaptureServiceTests.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Tests%2FEmbraceCoreTests%2FCapture%2FUX%2FView%2FViewCaptureServiceTests.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvRW1icmFjZUNvcmVUZXN0cy9DYXB0dXJlL1VYL1ZpZXcvVmlld0NhcHR1cmVTZXJ2aWNlVGVzdHMuc3dpZnQ=) | `100.00% <100.00%> (ø)` | | | [Tests/TestSupport/XCTestCase+WaitHelpers.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Tests%2FTestSupport%2FXCTestCase%2BWaitHelpers.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-VGVzdHMvVGVzdFN1cHBvcnQvWENUZXN0Q2FzZStXYWl0SGVscGVycy5zd2lmdA==) | `95.83% <100.00%> (ø)` | | | [...ore/Capture/UX/View/UIViewController+Embrace.swift](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree&filepath=Sources%2FEmbraceCore%2FCapture%2FUX%2FView%2FUIViewController%2BEmbrace.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io#diff-U291cmNlcy9FbWJyYWNlQ29yZS9DYXB0dXJlL1VYL1ZpZXcvVUlWaWV3Q29udHJvbGxlcitFbWJyYWNlLnN3aWZ0) | `93.75% <93.75%> (ø)` | | | ... and [8 more](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io) | | ... and [9 files with indirect coverage changes](https://app.codecov.io/gh/embrace-io/embrace-apple-sdk/pull/126/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=embrace-io)