enh(navigator-observer): make new trace id on navigation opt-in instead of opt-out#3657
Conversation
Creating a fresh trace on each route push/pop/replace by default can break trace continuity for users who don't expect it. Flip the default of enableNewTraceOnNavigation to false; users who want the old behavior can opt in. Refs #3589 Co-Authored-By: Claude <[email protected]>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Enhancements
Internal ChangesDeps
🤖 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 #3657 +/- ##
==========================================
+ Coverage 86.96% 91.80% +4.84%
==========================================
Files 321 102 -219
Lines 10802 3479 -7323
==========================================
- Hits 9394 3194 -6200
+ Misses 1408 285 -1123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
📲 Install BuildsAndroid
|
iOS Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| f761369 | 1261.69 ms | 1277.82 ms | 16.12 ms |
| 9b99523 | 1256.06 ms | 1270.33 ms | 14.27 ms |
| e45c0e1 | 1269.08 ms | 1278.83 ms | 9.75 ms |
| e2d675d | 1238.48 ms | 1242.76 ms | 4.28 ms |
| 101a9c7 | 1225.80 ms | 1236.04 ms | 10.25 ms |
| dc53d48 | 1252.06 ms | 1255.61 ms | 3.55 ms |
| 027fcfd | 1239.04 ms | 1243.65 ms | 4.61 ms |
| 7cfee3b | 1260.90 ms | 1273.14 ms | 12.24 ms |
| 1ce780b | 1252.49 ms | 1256.17 ms | 3.68 ms |
| 765aa8b | 1259.09 ms | 1269.90 ms | 10.82 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| f761369 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| 9b99523 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| e45c0e1 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| e2d675d | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| 101a9c7 | 5.73 MiB | 6.17 MiB | 455.47 KiB |
| dc53d48 | 5.65 MiB | 6.09 MiB | 446.96 KiB |
| 027fcfd | 5.73 MiB | 6.17 MiB | 455.48 KiB |
| 7cfee3b | 20.70 MiB | 22.46 MiB | 1.75 MiB |
| 1ce780b | 5.66 MiB | 6.10 MiB | 451.58 KiB |
| 765aa8b | 7.86 MiB | 9.44 MiB | 1.58 MiB |
Android Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 7b21e8b | 467.74 ms | 466.24 ms | -1.50 ms |
| 827bf09 | 475.40 ms | 547.14 ms | 71.74 ms |
| f872f8e | 402.38 ms | 416.20 ms | 13.82 ms |
| a69a51f | 437.18 ms | 450.60 ms | 13.42 ms |
| 8bfae64 | 370.78 ms | 369.15 ms | -1.63 ms |
| cc4e375 | 426.15 ms | 482.34 ms | 56.19 ms |
| e1ab497 | 429.30 ms | 439.00 ms | 9.70 ms |
| 9b99523 | 456.91 ms | 490.55 ms | 33.64 ms |
| 1777727 | 438.67 ms | 447.11 ms | 8.44 ms |
| 1f639ee | 429.98 ms | 476.60 ms | 46.62 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 7b21e8b | 13.93 MiB | 15.00 MiB | 1.06 MiB |
| 827bf09 | 6.54 MiB | 7.53 MiB | 1015.27 KiB |
| f872f8e | 13.93 MiB | 15.18 MiB | 1.25 MiB |
| a69a51f | 13.93 MiB | 15.06 MiB | 1.13 MiB |
| 8bfae64 | 14.09 MiB | 15.28 MiB | 1.19 MiB |
| cc4e375 | 6.54 MiB | 7.69 MiB | 1.15 MiB |
| e1ab497 | 13.93 MiB | 15.06 MiB | 1.13 MiB |
| 9b99523 | 6.54 MiB | 7.69 MiB | 1.15 MiB |
| 1777727 | 14.30 MiB | 15.49 MiB | 1.19 MiB |
| 1f639ee | 13.93 MiB | 15.00 MiB | 1.06 MiB |
There was a problem hiding this comment.
Pull request overview
Updates SentryNavigatorObserver to avoid starting a fresh trace on every navigation event by default, preserving trace continuity unless explicitly opted in.
Changes:
- Flip
enableNewTraceOnNavigationdefault fromtruetofalseinSentryNavigatorObserver. - Update and expand navigator observer trace tests to reflect the new default and verify opt-in behavior still works.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/flutter/lib/src/navigation/sentry_navigator_observer.dart | Changes the default for enableNewTraceOnNavigation and updates the API docs accordingly. |
| packages/flutter/test/navigation/sentry_navigator_observer_traces_test.dart | Adjusts existing tests and adds coverage to validate both default-disabled and explicitly-enabled behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 58f5a7f. Configure here.

📜 Description
Creating a fresh trace id on each route push/pop/replace by default can break trace continuity for users who don't expect it. And through experience the default (trace by session) is much more useful and understandable.
Flip the default of enableNewTraceOnNavigation to false; users who want the old behavior can opt in.
💡 Motivation and Context
Closes #3589
💚 How did you test it?
Change existing test
📝 Checklist
sendDefaultPiiis enabled