You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(flutter): Update Flutter routing instrumentation for Router, GoRouter, and AutoRoute (#17153)
<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->
## DESCRIBE YOUR PR
Expands the routing instrumentation docs to cover all Flutter navigation
approaches: imperative Navigator, declarative Router API, GoRouter, and
auto_route. Clarifies that GoRouter falls back to the route path when no
name is set, and that auto_route generates route names automatically.
Closesgetsentry/sentry-dart#3565Closesgetsentry/sentry-dart#3590
## IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+
## SLA
- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!
## PRE-MERGE CHECKLIST
*Make sure you've checked the following before merging your changes:*
- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)
---------
Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com>
Sentry's routing instrumentation for Flutter automatically tracks and reports page navigation events in your app.
14
-
It supports both [traditional Flutter routing](https://docs.flutter.dev/ui/navigation) and the [GoRouter](https://pub.dev/packages/go_router) package.
14
+
It supports imperative navigation (`Navigator.push()`), the declarative `Router` API (`MaterialApp.router`), and popular routing packages like [GoRouter](https://pub.dev/packages/go_router) and [auto_route](https://pub.dev/packages/auto_route).
15
15
16
16
<Alert>
17
17
@@ -29,11 +29,12 @@ Before starting, ensure:
29
29
30
30
## Configure
31
31
32
-
### 1. Add `SentryNavigationObserver`
32
+
### 1. Add `SentryNavigatorObserver`
33
33
34
-
Add an instance of `SentryNavigationObserver` to your application's `navigatorObservers`.
34
+
How you add `SentryNavigatorObserver` depends on which navigation approach you use.
By default the application's main route name is `"/"`.
91
-
The instrumentation sets the span `operation` to `navigation` and the span `name` to the provided route name.
92
-
For transactions to be created and breadcrumbs to be added when navigation changes, you need to provide route names:
164
+
The instrumentation sets the span `operation` to `ui.load` and the span `name` to the provided route name.
93
165
94
-
- Flutter routing: use `RouteSettings` and set the name in the constructor.
95
-
- GoRouter: use the `name` parameter to set the route name.
166
+
How you define route names depends on your navigation approach:
167
+
168
+
-**Navigator (imperative)**: Pass a `name` in the `RouteSettings` when pushing routes.
169
+
-**Router**: Set the `name` on the `Page` objects you return in your `pages` list (for example, `MaterialPage(name: 'My Widget', child: ...)`).
170
+
-**GoRouter**: GoRouter automatically uses the route `path` as the name. You can optionally set the `name` parameter on your `GoRoute` to override it.
171
+
-**auto_route**: Route names are generated automatically from your `@RoutePage()` annotations — no extra configuration needed.
96
172
97
173
<Alert>
98
174
99
-
Make sure that you set the route name for all routes.
100
-
If you do not set the route name, the SDK will not instrument performance insights such as [TTID](/platforms/dart/guides/flutter/integrations/routing-instrumentation/#time-to-initial-display) or [TTFD](/platforms/dart/guides/flutter/integrations/routing-instrumentation/#time-to-full-display) or create breadcrumbs for the route.
175
+
If the SDK cannot determine a route name, it will not create transactions, breadcrumbs, or performance insights such as [TTID](/platforms/dart/guides/flutter/integrations/routing-instrumentation/#time-to-initial-display) or [TTFD](/platforms/dart/guides/flutter/integrations/routing-instrumentation/#time-to-full-display) for that route.
101
176
102
177
</Alert>
103
178
104
-
```dart {tabTitle: Flutter Routing}
179
+
```dart {3} {tabTitle: Navigator}
105
180
MaterialPageRoute(
106
181
builder: (BuildContext context) => MyWidget(),
107
182
settings: RouteSettings(name: 'My Widget'),
108
183
)
109
184
```
110
185
111
-
```dart {tabTitle: GoRouter}
112
-
GoRoute(
113
-
path: 'mywidget',
186
+
```dart {3} {tabTitle: Router}
187
+
// Set the name on the Page objects in your RouterDelegate's pages list.
188
+
MaterialPage(
114
189
name: 'My Widget',
190
+
child: MyWidget(),
191
+
)
192
+
```
193
+
194
+
```dart {4-5} {tabTitle: GoRouter}
195
+
// The path is used as the route name by default.
196
+
// You can optionally set name to override it.
197
+
GoRoute(
198
+
path: '/mywidget',
199
+
name: 'My Widget', // optional, falls back to path
// Route names are auto-generated from your page annotations.
208
+
// No additional configuration is needed.
209
+
@RoutePage()
210
+
class MyWidgetPage extends StatelessWidget {
211
+
// ...
212
+
}
213
+
```
214
+
121
215
## Time to Initial Display
122
216
123
-
Time to initial display (TTID) provides insight into how long it takes your Widget to launch and draw their first frame.
124
-
This is measured by adding a span for navigation to a Widget.
217
+
Time to initial display (TTID) provides insight into how long it takes your Widget to launch and draw their first frame.
218
+
This is measured by adding a span for navigation to a Widget.
125
219
The SDK then sets the span operation to `ui.load.initial-display` and the span description to the Widget's route name, followed by initial display (for example, `MyWidget initial display`).
126
220
127
221
TTID is enabled by default.
128
222
129
223
## Time to Full Display
130
224
131
-
Time to full display (TTFD) provides insight into how long it would take your Widget to launch and load all of its content.
132
-
This is measured by adding a span for each navigation to a Widget.
225
+
Time to full display (TTFD) provides insight into how long it would take your Widget to launch and load all of its content.
226
+
This is measured by adding a span for each navigation to a Widget.
133
227
The SDK then sets the span operation to `ui.load.full-display` and the span description to the Widget's route name, followed by full display (for example, `MyWidget full display`).
134
228
135
229
TTFD is disabled by default. To enable TTFD measurements, follow these steps:
@@ -255,7 +349,7 @@ class MyWidgetState extends State<MyWidget> {
255
349
256
350
Use the navigator to transition to your widget. This should create and send a transaction named after the widget's route.
257
351
258
-
```dart {tabTitle: Flutter Routing}
352
+
```dart {tabTitle: Navigator}
259
353
import 'package:flutter/material.dart';
260
354
import 'my_widget.dart';
261
355
@@ -269,13 +363,25 @@ Navigator.push(
269
363
);
270
364
```
271
365
366
+
```dart {tabTitle: Router}
367
+
// Update your delegate's state to trigger a page change.
368
+
final delegate = Router.of(context).routerDelegate as MyRouterDelegate;
0 commit comments