Skip to content
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

Improving instrumentation around UIViewController #126

Merged
merged 3 commits into from
Nov 28, 2024

Conversation

NachoEmbrace
Copy link
Contributor

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.

@NachoEmbrace NachoEmbrace requested a review from a team as a code owner November 20, 2024 18:31
Copy link

github-actions bot commented Nov 20, 2024

Dependency Review

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

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Copy link

github-actions bot commented Nov 20, 2024

Warnings
⚠️ No CHANGELOG entry added.

Generated by 🚫 Danger Swift against 0bba885

Comment on lines 123 to 129
guard let id = vc.emb_identifier,
let span = self.viewDidLoadSpans[id] else {
return
}

span.end()
self.viewDidLoadSpans[id] = nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: to prevent from accessing twice the dictionary (which also has the locking mechanism) maybe you can do something like:

Suggested change
guard let id = vc.emb_identifier,
let span = self.viewDidLoadSpans[id] else {
return
}
span.end()
self.viewDidLoadSpans[id] = nil
guard let id = vc.emb_identifier,
let span = self.viewDidLoadSpans.removeValue(forKey: id) else {
return
}
span.end()

Copy link

codecov bot commented Nov 26, 2024

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 ⚠️
.../View/Protocols/InstrumentableViewController.swift 0.00% 19 Missing ⚠️
...Core/Capture/UX/View/ViewCaptureServiceError.swift 38.46% 16 Missing ⚠️
...Core/Capture/UX/View/UIViewControllerHandler.swift 97.06% 9 Missing ⚠️
...braceCore/Capture/UX/View/ViewCaptureService.swift 90.62% 9 Missing ⚠️
...w/Protocols/CaptureServices+UIViewController.swift 92.53% 5 Missing ⚠️
...Capture/UX/View/UIViewControllerHandlerTests.swift 98.93% 4 Missing ⚠️
...UX/View/Protocols/InteractableViewController.swift 0.00% 3 Missing ⚠️
...ore/Capture/UX/View/UIViewController+Embrace.swift 93.75% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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 Coverage Δ
Sources/EmbraceCore/Capture/CaptureServices.swift 79.34% <100.00%> (+0.93%) ⬆️
...tions/PushNotificationCaptureService+Options.swift 50.00% <ø> (ø)
...Protocols/EmbraceViewControllerCustomization.swift 50.00% <100.00%> (ø)
...e/Capture/UX/View/ViewCaptureService+Options.swift 100.00% <100.00%> (ø)
Sources/EmbraceCore/Public/Embrace+OTel.swift 70.75% <ø> (ø)
.../Capture/UX/View/MockUIViewControllerHandler.swift 100.00% <100.00%> (ø)
...X/View/MockUIViewControllerHandlerDataSource.swift 100.00% <100.00%> (ø)
...ests/Capture/UX/View/ViewCaptureServiceTests.swift 100.00% <100.00%> (ø)
Tests/TestSupport/XCTestCase+WaitHelpers.swift 95.83% <100.00%> (ø)
...ore/Capture/UX/View/UIViewController+Embrace.swift 93.75% <93.75%> (ø)
... and 8 more

... and 9 files with indirect coverage changes

@NachoEmbrace NachoEmbrace merged commit d52496a into main Nov 28, 2024
5 of 6 checks passed
@NachoEmbrace NachoEmbrace deleted the view_controller_instrumentation branch November 28, 2024 15:32
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.

2 participants