feat: record navigations and first draw for swiftui/uikit #1321
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1321"
general
weight: 0.35
nachoBonafonte
Screen and navigation instrumentation for UIKit and SwiftUI
Author williazz · Reviewers robert-northmind, nachoBonafonte · Status open, awaiting approval · Updated 2026-12-03
This description is the design doc. It compares main at
f299ff7cwith this PR's head,06f34357. The API reference that used to sit here moved to one comment; the same text is inScreen/README.md. Watch the recording of the scenarios on a Revyl simulator.Background
An app moves between screens through container calls: a navigation controller push, a sheet, a tab switch. UIKit and SwiftUI then run the same lifecycle for every screen they show, and the SDK's processors stamp attributes on each span and log record before the exporter sends it.
!Today: the push runs, the SDK hears none of it
1. App code calls a container, which loads the new screen (
viewDidLoad, or a SwiftUIbody).2. UIKit or SwiftUI calls
viewWillAppear, Core Animation draws the first frame, andviewDidAppearfollows.3. The session, user and vitals processors stamp each span as it starts.
SessionSpanProcessor.onStartaddssession.id; nothing adds a screen.4. AppLaunch reads one first frame per process, for
app.startonly (FirstFrameReader.swift).The semantic conventions already name the attribute:
case screenName = "app.screen.name". Nothing in the SDK sets it.How peers do it
| SDK | Hook | Current screen | Navigation record | Draw time per screen |
| --- | --- | --- | --- | --- |
| OpenTelemetry Android | Activity and fragment lifecycle callbacks (
VisibleScreenTrackerImpl.kt) |app.screen.nameon every span (ScreenAttributesSpanProcessor.kt) |app.navigation.completedefined inevents.yaml; emission not checked | Lifecycle spans, Created to Resumed (README) || Sentry Cocoa | Swizzles
loadViewandviewDidLoad(helper) | not checked | not checked |ui.load.initial_display(SentrySpanOperation.m) || Datadog iOS | UIKit predicate; SwiftUI
.trackRUMView()ononAppear(modifier) | One app-level view stack (RUM_FEATURE.md) | One RUM view per screen | not checked || Sentry Flutter |
RouteObserverpush, replace, pop (observer) | not checked |navigationbreadcrumbs | not checked |This PR takes its names and event shape from OpenTelemetry Android and its draw-time idea from Sentry's initial display. Like Datadog, it keeps one stack for the app, not one per window.
Problem statement
The lifecycle runs on every navigation, but no SDK component listens between it and the processors. Every span and log record leaves without a screen, the path through the app is lost, and a slow screen looks the same as a fast one.
!Bottleneck: no listener between the lifecycle and the processors
Sheets make it harder: when a sheet is dismissed, neither UIKit nor SwiftUI tells the presenter it reappeared, so a naive tracker keeps the sheet as the current screen.
A solution must:
1. Stamp the current screen on every span and log record.
2. Record each navigation with the previous screen, its type and its position in the session.
3. Record time to first frame per screen instance, comparable with
app.start.4. Cover UIKit, SwiftUI, apps that mix them, and screens no front end sees.
5. Let each signal turn off without running.
6. Add to the SDK without changing anything that exists.
Out of scope
ui.load.full_displayneeds the app to say when data arrived; this PR stops at the first frame.developmentstability, asapp.startdid in #1275.Proposal
Add a
ScreenInstrumentationmodule, ported from AwsOtelSwift's UIKit and SwiftUI instrumentation. Both front ends report into one tracker, which names the current screen, numbers each navigation and times each first draw.!Proposed: front ends feed one tracker, which feeds the processors
1. Front ends report each screen.
ScreenInstrumentation.install(configuration:)swizzles UIKit's lifecycle unlessuiKitisnil. SwiftUI views opt in with.otelScreen, which swizzles nothing.2. One stack serves both.
ScreenTrackerpushes a screen when it appears and removes it when it disappears; the newest visible entry is the current screen, so dismissing a sheet makes its presenter current again.3. Time to first draw. Each instance records one
app.screen.time_to_first_drawspan from load to the first frame, read with the display-link codeapp.startuses (recordTimeToFirstDraw).4. Navigation event. A change of current screen emits
app.navigation.completewith the screen reached, the screen left,app.navigation.typeandapp.navigation.sequence(NavigationSequence.next). Setting the screen to itself emits nothing.5. Processors stamp the screen.
ScreenSpanProcessorandScreenLogRecordProcessoraddapp.screen.nameto every span and log record.What changes
| Part | Before | After |
| --- | --- | --- |
|
app.screen.name| Defined, never set | On every span and log record || Navigation | Not recorded |
app.navigation.completewith previous screen, type and sequence || Screen draw time | Only
app.start, once per process |app.screen.time_to_first_drawper screen instance || Manual screens | None |
ScreenTrackerProvider.getInstance().setCurrent(screen:), reported asmanual|| Opt-outs | None |
uiKit: nil,recordsNavigation: false, or skipinstall|How UIKit decides a screen
Not every view controller is a screen. Containers such as navigation and tab controllers only hold screens, so
tracksScreenskips them, along with system controllers. An app overrides the decision per class withScreenTrackingCustomization. UIKit reads the navigation type from the container call that caused the change:push,pop,pop_to,replace,reset,modal,dismissorswitch. The values extend the W3C Navigation API'snavigationType.How one stack serves both front ends
UIKit and SwiftUI call the same tracker, so an app that hosts SwiftUI inside UIKit, or the reverse, sees one path.
appearanddisappearedit the stack, andsettlemakes the newest visible screen current and reports a change only when it moved. SwiftUI has no container calls to read, so it infers push, pop andpop_tofrom@Statelifetimes and the rest from opt-in modifiers. Sequence numbers are taken on the main queue (NavigationSequence.swift), so a gap in them shows a lost event.How time to first draw is measured
UIKit starts the span at
viewDidLoad, or atviewWillAppearfor a screen built before it became current, such as a preloaded tab. SwiftUI starts it when the parent builds theScreenTraceView. Both end at the first frame the display link reports. A screen the user returns to is already drawn and records nothing; a screen sent to the background before its first frame records none either.An example event
Measure it
The goal is that every span and log record carries a screen, and that a navigation path has no gaps. Check it in a backend by counting spans without
app.screen.nameafter the first screen appears, and by looking for missingapp.navigation.sequencenumbers within a session. No baseline exists, since today every span lacks a screen. Runtime overhead of the swizzles and processors is not measured.Ship it
One PR, opt-in: nothing runs until an app calls
installor adds.otelScreen, so it works beside the previous release. Tests on this head:| Run | Result |
| --- | --- |
|
swift test --enable-all-traits --filter ScreenTests, macOS | 99 pass; the UIKit suite compiles out on macOS ||
xcodebuild test -only-testing:ScreenTests, iPhone simulator | 153 pass ||
screen-navigationlaunch on Revyl simulators | Pass on iOS 26.2, 26.5 and 27.0; 5 of 6 runs on iOS 18.5 |docs/limits.mdholds the full limits and test notes.Risks
uiKit: nilturns UIKit tracking off and leaves SwiftUI and manual screens working.ScreenTrackingCustomizationlets an app override them.pop_tofrom[List, Detail, Author]to[List]; the cause is not known. It shows up as a sequence gap, not a wrong screen.superis invisible.Open decisions
developmentnames should wait for the semconv SIG before merge, or ship asapp.startdid.Alternate solutions
Do nothing
Apps keep naming screens by hand in span attributes, with no shared name or event, and backends cannot compare screens across apps. Rejected: the convention already exists and Android fills it.
Separate UIKit and SwiftUI modules
Revision 1 shipped the UIKit and SwiftUI front ends separately. A late SwiftUI reveal could replace a newer UIKit screen, and whether a dismissed sheet revealed its presenter depended on which front end reported it. Rejected after Robert's review:
70ab8f91consolidated them into one module and one stack.Stamp only
app.screen.nameAndroid core stamps the screen and leaves navigation to instrumentation. That meets requirement 1 and misses 2 and 3: the path and the draw time are the reason to track screens at all.
Swizzle SwiftUI too
SwiftUI views are value types, not Objective-C classes, so there is no view method to swizzle. Swizzling
UIHostingControllerwould name the host, not the view the user sees. Rejected in favor of the opt-in.otelScreenmodifier, which Datadog's.trackRUMView()also uses.Glossary
pushViewControllerorpresent.ScreenTracker.app.navigation.sequence, a navigation's position in the session.