Skip to content

Commit 582c163

Browse files
authored
feat: Document Flutter Auto Transactions (#4582)
1 parent 08cbfc7 commit 582c163

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/platforms/flutter/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,55 @@ The span finishes once the request has been executed. The span `status` depends
2323
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and SentryEvent will be linked when viewing it on the **Issue Details** page in sentry.io.
2424

2525
For more information see our [SentryHttpClient integration](/platforms/dart/usage/advanced-usage/#performance-monitoring-for-http-requests).
26+
27+
### Routing Instumentation
28+
29+
<Note>
30+
31+
Supported in Sentry's Dart SDK version `6.3.0-beta.1` and above.
32+
33+
</Note>
34+
35+
Automatic routing instrumentation can be enabled by adding an instance of `SentryNavigationObserver` to your application's `navigatorObservers`. Transactions are started automatically when routing to new pages in your application.
36+
37+
```dart
38+
import 'package:flutter/material.dart';
39+
import 'package:sentry_flutter/sentry_flutter.dart';
40+
41+
return MaterialApp(
42+
title: 'Home',
43+
home: HomeScreen(),
44+
navigatorObservers: [
45+
SentryNavigatorObserver()
46+
],
47+
);
48+
```
49+
50+
The main route of your application will have the name `root "/"`. In order for transactions to be created automatically when navigation changes, you need to provide route names through your routes setttings parameter.
51+
52+
```dart
53+
import 'package:flutter/material.dart';
54+
55+
MaterialPageRoute(
56+
builder: (BuildContext context) => Settings(),
57+
settings: RouteSettings(name: 'Settings'),
58+
)
59+
```
60+
61+
The SDK sets the span `operation` to `navigation` and the `name` to the one provided in `RouteSettings`.
62+
63+
Transactions will be bound to the scope if no other transaction is currently bound to it.
64+
65+
The started transactions will idle for a fixed amount of time, for which the default is `three seconds`.
66+
67+
Child spans started will be attached to the transaction. If they run longer than the idle time, the transaction will be extended and finished when all its children are complete.
68+
69+
You can also opt out of this behaviour by setting `enableAutoTransactions` to false in the `SentryNavigatorObserver` constructor. You might do this when you only want to use navigation breadcrumbs, which can be enabled by setting the constructor parameter `setRouteNameAsTransaction` to `true`.
70+
71+
```dart
72+
/// Only track navigation breadcrums
73+
SentryNavigatorObserver(
74+
enableAutoTransactions: false,
75+
setRouteNameAsTransaction: true
76+
)
77+
```

0 commit comments

Comments
 (0)