Repository navigation
fix(flutter): Parent HTTP spans to the new route - #4155
Conversation
Hand off app-start scope on navigation while TTFD is pending and track current route replacements in both tracing modes. Fixes #4154 Co-Authored-By: OpenAI Codex <noreply@openai.com>
Semver Impact of This PRπ’ Patch (bug fixes) π Changelog PreviewThis is how your changes will appear in the changelog. FixesFlutter
Other
DependenciesDeps
Internal Changes
π€ This preview updates automatically when you update the PR. |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4155 +/- ##
==========================================
+ Coverage 89.11% 93.15% +4.03%
==========================================
Files 354 119 -235
Lines 12795 4833 -7962
==========================================
- Hits 11402 4502 -6900
+ Misses 1393 331 -1062
Flags with carried forward coverage won't be shown. Click here to find out more. β View full report in Codecov by Harness. |
Keep the prepared app-start display through early route replacements. Omit raw replacement arguments from static transaction data. Refs #4154 Co-Authored-By: OpenAI Codex <noreply@openai.com>
There was a problem hiding this comment.
π’ Approval recommended
No active review issues block the route-tracking and HTTP-span parenting changes.
No open issues π
What changed in this PR
Fixes #4154 by keeping HTTP spans attached to the incoming Flutter route instead of the initial app-start transaction while full-display timing remains pending.
Changes:
- Updates route tracking for pushes and named current-route replacements while preserving unrelated scope bindings.
- Reuses reserved app-start display tracking for early replacements and avoids copying raw replacement arguments into static transactions.
- Adds widget tests for static and streaming HTTP parenting, delayed timing, consecutive navigation, and background replacements.
| File | Description |
|---|---|
packages/βflutter/βtest/βnavigation/βsentry_navigator_observer_test.dart |
Adds HTTP-parenting, replacement, timing, and privacy regression tests. |
packages/βflutter/βtest/βmocks.mocks.dart |
Updates the mock for prepared app-start route renaming. |
packages/βflutter/βlib/βsrc/βnavigation/βtime_to_display_tracker.dart |
Releases the initial displayβs scope binding and supports renaming reserved transactions. |
packages/βflutter/βlib/βsrc/βnavigation/βtime_to_display_tracker_v2.dart |
Supports renaming prepared streaming app-start display spans. |
packages/βflutter/βlib/βsrc/βnavigation/βsentry_navigator_observer.dart |
Tracks current replacements and prevents older transaction callbacks from clearing newer state. |
Review effort: Balanced
Unbind the app-start root and end its pending display spans on every push or current replacement, including unnamed routes, instead of leaving its TTFD span to the 30s timeout. clear() no longer touches the scope. Only a replacement of the route that named the app start takes over its reservation, so nested navigators can't rename it. Replacing with / starts no transaction, matching didPush. Merge the duplicate app-start rename methods and restructure the tests. Refs #4154 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record route_settings_arguments on replacement transactions like didPush does. The didReplace breadcrumb already carries them, so omitting them only made push and replace inconsistent. Refs #4154 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Release the app-start root only when a route display starts, instead of on every push or replacement. Releasing on unnamed routes ended the app-start TTFD as deadline_exceeded when a dialog opened over the initial screen, and dropped that screen's HTTP spans because nothing was left bound to the scope. This matches streaming, where trackRoute ends the previous display, and ordinary route transactions, which unnamed routes leave running. Refs #4154 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Splitting the V2 tracker test dropped the check that prepareAppStart marks the route name as pending. Only one observer widget test still caught a regression there, and not by name. Refs #4154
|
After reviewing it, I found some behaviour differences compared to Sentry React Native that may result in anomalies. |
|
I spotted an edge case here when What's affected:
With the flag off these spans previously had no parent and were dropped, so the result is misattributed spans, not lost data. I'd call it low to medium severity. I reproduced it with a real Navigator:
|
lucas-zimerman
left a comment
There was a problem hiding this comment.
The two comments that I wrote applies here, but they also happen on main so they are somewhat unrelated, feel free to do a follow-up PR or just open an issue to track them.
With enableAutoTransactions disabled, navigating to a named route skipped all display handling, so the app start stayed bound to the scope (static) or active (streaming) and spans from later screens parented to it until its TTFD timed out. End the previous display before checking the flag, in both trace lifecycles. The flag now only controls whether a new route transaction or span starts.
Navigating to a named route before first-frame timing arrives ends the prepared streaming app-start span. When the timing arrived afterwards, trackAppStart found nothing prepared, started a fresh idle span, and spans from the current screen parented to it. Skip recording when nothing is prepared anymore, as static already does.
Every push or replacement cleared the app-start route, including ones that start no display, such as dialogs. Replacing the initial route after a dialog opened and closed before first-frame timing then dropped the app-start reservation and started a separate route transaction. Clear the handoff only when a new route display takes over.
π¨ Detected changes in high risk code π¨High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:
|
With auto transactions disabled in streaming mode, navigating to a named route called cancelCurrentRoute, which ends whatever idle span the hub holds. That cut short user-interaction spans, such as the tap that pushed the route. Track the app-start span and end only that one. With auto transactions enabled, trackRoute still ends the current route span as before.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
β Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fe57c4e. Configure here.

π Description
Hand the scope over from the app-start
root /transaction when the next route display starts, so HTTP spans from later screens parent to the new route instead of the app start.deadline_exceeded, instead of leaving them to the 30s TTFD timeout. Streaming already follows this rule throughtrackRoute, and it is how sentry-java and sentry-cocoa end the previous screen's display.enableAutoTransactionsdisabled: navigating to a named, non-root route ends the previous display (the app start included) in both lifecycles, and the flag only decides whether a new route transaction or span starts. Before, the app start stayed bound to the scope (static) or active (streaming), so spans from later screens, including manualSentry.getSpan()?.startChild(...)children, attached to it until its TTFD timed out. AreportFullyDisplayed()for the initial screen after leaving it is no longer recorded, the same as with auto transactions enabled.pushReplacement/replaceof the current route now starts aui.loadtransaction (static) or route span (streaming), likepush. Replacing with/starts none, matchingpush.route_settings_arguments, likedidPush.π‘ Motivation and Context
The app-start transaction held the scope until its TTFD span timed out, so HTTP spans from later screens attached to
root /, which could last close to 30s.Fixes #4154
Known limitation (pre-existing, unchanged here): an unnamed route, such as a
MaterialPageRoutewithout settings, doesn't end the previous display in either lifecycle, whether that is the app start or another route. Its spans keep parenting to the previous screen while that transaction or span is still open. The same goes for a later navigation to/(e.g. a splash screen replaced by home after the first frame): no new display starts, so its spans stay on the app start.π How did you test it?
Widget tests cover static and streaming HTTP parenting on push and replacement (including past the TTFD deadline and across consecutive pushes), ending the app-start TTFD span on navigation, a dialog over the initial screen (TTFD stays reportable and HTTP spans stay on the app start), early replacement with delayed first-frame timing, nested-navigator replacements, replacing with
/, replacement arguments being recorded, and ending the app start on push withenableAutoTransactionsdisabled (static scope released and TTFDdeadline_exceeded; streaming app-start span ended and no longer active). Unit tests coverTimeToDisplayTracker.releaseInitialDisplay.Also run manually on an iOS simulator with native app start, static lifecycle and TTFD enabled, following the issue's steps (never report fully displayed on the initial screen, push
/next, make two HTTP requests). Before this changeroot /kept the scope, received both HTTP spans and was only sent after its TTFD timeout, while/nexthad none. With it,root /is sent on navigation without HTTP spans and/nextcarries both.π Checklist
Changelog Entry
root /transaction until its TTFD timeout (Initial root / transaction keeps scope after navigationΒ #4154)pushReplacement/replaceof the current route now starts aui.loadtransaction (static) or route span (streaming), likepushenableAutoTransactionsdisabled, navigating to a named route now ends the app-start display (TTID/TTFD end asdeadline_exceededin static mode), so spans from later screens no longer attach to the app start