Skip to content

Commit 8ebae05

Browse files
flutter: improve session and screenshots docs (#11708)
* improve docs * update * update * update snippet * update doc * update screenshots * Update docs/platforms/flutter/configuration/options.mdx Co-authored-by: Alex Krawiec <[email protected]> * Update docs/platforms/flutter/configuration/releases.mdx Co-authored-by: Alex Krawiec <[email protected]> * Update platform-includes/configuration/auto-session-tracking/flutter.mdx Co-authored-by: Alex Krawiec <[email protected]> * Update platform-includes/enriching-events/attach-screenshots/flutter.mdx Co-authored-by: Alex Krawiec <[email protected]> * Update platform-includes/configuration/auto-session-tracking/flutter.mdx Co-authored-by: Alex Krawiec <[email protected]> * update code snippets * update code snippets * update code snippets --------- Co-authored-by: Alex Krawiec <[email protected]>
1 parent d8dce06 commit 8ebae05

File tree

8 files changed

+70
-100
lines changed

8 files changed

+70
-100
lines changed

docs/platforms/dart/configuration/releases.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,14 @@ Setting the release name tags each event with that release name. We recommend th
5757
If you don't tell Sentry about a new release, Sentry will automatically create a release entity in the system the first time it sees an event with that release ID.
5858

5959
After configuring your SDK, you can install a repository integration or manually supply Sentry with your own commit metadata. Read our documentation about [setting up releases](/product/releases/setup/) for further information about integrations, associating commits, and telling Sentry when deploying releases.
60+
61+
## Release Health
62+
63+
<Note>
64+
65+
Looking for Flutter release health? [See the Flutter documentation](/platforms/flutter/configuration/releases/#release-health).
66+
67+
</Note>
68+
69+
Monitoring release health is currently not supported for pure Dart applications.
70+

docs/platforms/dart/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Verify that your app is sending events to Sentry by adding the following snippet
6868
import 'package:sentry/sentry.dart';
6969
7070
try {
71-
aMethodThatMightFail();
71+
throw Exception('Sentry Test Error');
7272
} catch (exception, stackTrace) {
7373
await Sentry.captureException(
7474
exception,

docs/platforms/flutter/configuration/options.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ This option can be overridden using <PlatformIdentifier name="in-app-include" />
151151
<ConfigKey name="attach-screenshot">
152152

153153
Takes a screenshot of the application when an error happens and includes it as an attachment.
154+
Enable this option by setting <PlatformIdentifier name="attach-screenshot" /> to `true` and wrapping your root widget with `SentryWidget(child: MyApp())`.
154155
Learn more about enriching events with screenshots in our <PlatformLink to="/enriching-events/screenshots/">Screenshots documentation</PlatformLink>.
155156

156157
</ConfigKey>

docs/platforms/flutter/configuration/releases.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ After configuring your SDK, you can install a repository integration or manually
6262

6363
Monitor the [health of releases](/product/releases/health/) by observing user adoption, usage of the application, percentage of [crashes](/product/releases/health/#crash), and [session data](/product/releases/health/#session). Release health will provide insight into the impact of crashes and bugs as it relates to user experience, and reveal trends with each new issue through the [Release Details](/product/releases/release-details/) graphs and filters.
6464

65+
In order to monitor release health, the SDK sends session data.
66+
6567
<Note>
6668

67-
Crash reporting and app hang detection are not available for watchOS.
69+
Release health in Flutter is only available for Android, iOS, and macOS.
6870

6971
</Note>
7072

71-
In order to monitor release health, the SDK sends session data.
72-
7373
### Sessions
7474

7575
A session represents the interaction between the user and the application. Sessions contain a timestamp, a status (if the session was OK or if it crashed), and are always linked to a release. Most Sentry SDKs can manage sessions automatically.

docs/platforms/flutter/enriching-events/screenshots/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This feature is only available for SDKs with a user interface, like the ones for
99

1010
## Enabling Screenshots
1111

12-
Because screenshots may contain <PlatformLink to="/data-management/sensitive-data/">PII</PlatformLink>, they are an opt-in feature. You can enable screenshots as shown below:
12+
Because screenshots may contain <PlatformLink to="/data-management/sensitive-data/">PII</PlatformLink>, they are an opt-in feature.
1313

1414
<PlatformContent includePath="enriching-events/attach-screenshots" />
1515

docs/platforms/flutter/integrations/routing-instrumentation.mdx

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Before starting, ensure:
3030

3131
Add an instance of `SentryNavigationObserver` to your application's `navigatorObservers`.
3232

33-
```dart {tabTitle: Flutter Routing}
33+
```dart {8} {tabTitle: Flutter Routing}
3434
import 'package:flutter/material.dart';
3535
import 'package:sentry_flutter/sentry_flutter.dart';
3636
@@ -43,7 +43,7 @@ return MaterialApp(
4343
);
4444
```
4545

46-
```dart {tabTitle: GoRouter}
46+
```dart {6} {tabTitle: GoRouter}
4747
import 'package:go_router/go_router.dart';
4848
import 'package:sentry_flutter/sentry_flutter.dart';
4949
@@ -62,21 +62,15 @@ For transactions to be created when navigation changes, you need to provide rout
6262
- Flutter routing: use `RouteSettings` and set the name in the constructor.
6363
- GoRouter: use the `name` parameter to set the route name.
6464

65-
```dart {tabTitle: Flutter Routing}
66-
import 'package:flutter/material.dart';
67-
import 'package:sentry_flutter/sentry_flutter.dart';
68-
65+
```dart {4} {tabTitle: Flutter Routing}
6966
/// Setting the route name is required
7067
MaterialPageRoute(
7168
builder: (BuildContext context) => MyWidget(),
7269
settings: RouteSettings(name: 'My Widget'),
7370
)
7471
```
7572

76-
```dart {tabTitle: GoRouter}
77-
import 'package:go_router/go_router.dart';
78-
import 'package:sentry_flutter/sentry_flutter.dart';
79-
73+
```dart {13} {tabTitle: GoRouter}
8074
final GoRouter _router = GoRouter(
8175
observers: [SentryNavigatorObserver()],
8276
routes: <RouteBase>[
@@ -110,8 +104,6 @@ There are two ways to set up TTID:
110104
The default setup is enabled automatically, but only provides an approximation of TTID. To set a more accurate TTID, manually wrap the desired widget with `SentryDisplayWidget`, as shown below:
111105

112106
```dart
113-
import 'package:sentry_flutter/sentry_flutter.dart';
114-
115107
SentryDisplayWidget(
116108
child: MyWidget(),
117109
)
@@ -129,23 +121,17 @@ TTFD is disabled by default. To enable TTFD measurements, follow these steps:
129121

130122
1. Enable the `enableTimeToFullDisplayTracing` option in the SDK configuration:
131123

132-
```dart
133-
import 'package:flutter/widgets.dart';
134-
import 'package:sentry_flutter/sentry_flutter.dart';
135-
136-
Future<void> main() async {
137-
await SentryFlutter.init(
138-
(options) => options.enableTimeToFullDisplayTracing = true,
139-
appRunner: () => runApp(MyApp()),
140-
);
141-
}
124+
```dart {3}
125+
await SentryFlutter.init(
126+
(options) {
127+
options.enableTimeToFullDisplayTracing = true;
128+
}, appRunner: () => runApp(MyApp()),
129+
);
142130
```
143131

144132
2. Report the span manually:
145133

146134
```dart
147-
import 'package:sentry_flutter/sentry_flutter.dart';
148-
149135
SentryFlutter.reportFullyDisplayed();
150136
```
151137

@@ -231,9 +217,6 @@ Log into [sentry.io](https://sentry.io) and open your project's performance page
231217
Adjust the duration before a routing transaction automatically finishes. The default is 3 seconds.
232218

233219
```dart
234-
import 'package:sentry_flutter/sentry_flutter.dart';
235-
236-
/// Change how long navigation transactions idle before being finished
237220
SentryNavigatorObserver(
238221
autoFinishAfter: Duration(seconds: 5)
239222
)
@@ -251,9 +234,6 @@ Set `enableAutoTransactions` to `false` if you only want to track navigation bre
251234
Enabled by default.
252235

253236
```dart
254-
import 'package:sentry_flutter/sentry_flutter.dart';
255-
256-
/// Only track navigation breadcrumbs
257237
SentryNavigatorObserver(
258238
enableAutoTransactions: false,
259239
)
@@ -265,9 +245,6 @@ Set `ignoreRoutes` if you want routes to be ignored and not processed by the nav
265245
Empty by default.
266246

267247
```dart
268-
import 'package:sentry_flutter/sentry_flutter.dart';
269-
270-
/// Ignore matching routes
271248
SentryNavigatorObserver(
272249
ignoreRoutes: ["/ignoreThisRoute", "/my/ignored/route"],
273250
)
@@ -280,9 +257,6 @@ An existing transaction in the scope 'CustomTransaction' will be renamed to 'MyW
280257
Disabled by default.
281258

282259
```dart
283-
import 'package:sentry_flutter/sentry_flutter.dart';
284-
285-
/// Override transaction name with route name
286260
SentryNavigatorObserver(
287261
setRouteNameAsTransaction: true,
288262
)
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
To benefit from the health data, you must use at least version 4.0.0 of the Flutter SDK.
22

3-
By default, the session is terminated once the application is in the background for more than 30 seconds. You can change the time out with the option named `sessionTrackingIntervalMillis`. It takes the amount in milliseconds. For example, to configure it to be 60 seconds:
3+
#### Session Timeout
44

5-
```dart
6-
import 'package:flutter/widgets.dart';
7-
import 'package:sentry_flutter/sentry_flutter.dart';
5+
By default, the session is terminated once the application is in the background for more than `30 seconds`. You can change this default by setting the `autoSessionTrackingInterval` option to a `Duration` of your choosing.
86

9-
Future<void> main() async {
10-
await SentryFlutter.init(
11-
(options) => options.autoSessionTrackingInterval = const Duration(milliseconds: 60000)
12-
appRunner: () => runApp(MyApp()),
13-
);
14-
}
7+
```dart {2}
8+
SentryFlutter.init((options) {
9+
options.autoSessionTrackingInterval = const Duration(seconds: 60)
10+
});
1511
```
1612

17-
If you'd like to opt out of this feature, you can do so using options.
13+
#### Disable Auto Session Tracking
1814

19-
```dart
20-
import 'package:flutter/widgets.dart';
21-
import 'package:sentry_flutter/sentry_flutter.dart';
15+
If you'd like to opt out of capturing sessions, set the `enableAutoSessionTracking` option to `false`. If you disable this feature, release health will not be available.
2216

23-
Future<void> main() async {
24-
await SentryFlutter.init(
25-
(options) => options.enableAutoSessionTracking = true, // it's enabled by default
26-
appRunner: () => runApp(MyApp()),
27-
);
28-
}
17+
```dart {2}
18+
SentryFlutter.init((options) {
19+
options.enableAutoSessionTracking = false;
20+
});
2921
```
Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,40 @@
1-
```dart
2-
import 'package:flutter/widgets.dart';
3-
import 'package:sentry_flutter/sentry_flutter.dart';
1+
Enable screenshots by setting the `attachScreenshot` option to `true` and wrap your root widget with `SentryWidget`.
42

5-
Future<void> main() async {
6-
await SentryFlutter.init(
7-
(options) {
8-
options.dsn = '___PUBLIC_DSN___';
9-
options.attachScreenshot = true;
10-
},
11-
appRunner: () => runApp(
12-
// Wrap your app widget with the [SentryWidget] widget.
13-
SentryWidget(
14-
child: MyApp(),
15-
),
3+
```dart {3, 6-8}
4+
await SentryFlutter.init(
5+
(options) {
6+
options.attachScreenshot = true;
7+
},
8+
appRunner: () => runApp(
9+
SentryWidget(
10+
child: MyApp(),
1611
),
17-
);
18-
}
12+
),
13+
);
1914
```
2015

21-
### Filtering Screenshots
16+
## Filtering Screenshots
2217

23-
You can filter your screenshots by using the `beforeScreenshot` callback.
24-
It is called before taking a screenshot and if the callback returns `false`, the screenshot will not be attached.
18+
You can filter your screenshots by using the `beforeScreenshot` callback, which is called before attaching a screenshot to an event. By default, the callback returns `true` which means that all screenshots are attached.
2519

26-
```dart
27-
import 'package:flutter/widgets.dart';
28-
import 'package:sentry_flutter/sentry_flutter.dart';
20+
If the callback returns `false`, the screenshot will not be attached.
2921

30-
Future<void> main() async {
31-
await SentryFlutter.init(
32-
(options) {
33-
options.dsn = '___PUBLIC_DSN___';
34-
options.attachScreenshot = true;
35-
options.beforeScreenshot = (event, {hint}) {
36-
// Return false if you don't want to attach the screenshot based on some condition.
37-
return true;
38-
};
39-
},
40-
appRunner: () => runApp(
41-
// Wrap your app widget with the [SentryWidget] widget.
42-
SentryWidget(
43-
child: MyApp(),
44-
),
22+
```dart {4-10}
23+
await SentryFlutter.init(
24+
(options) {
25+
options.attachScreenshot = true;
26+
options.beforeScreenshot = (event, {hint}) {
27+
// Based on some condition you can decide to attach the screenshot or drop it
28+
if (event.throwable is MyImportantException) {
29+
return true;
30+
}
31+
return false;
32+
};
33+
},
34+
appRunner: () => runApp(
35+
SentryWidget(
36+
child: MyApp(),
4537
),
46-
);
47-
}
38+
),
39+
);
4840
```

0 commit comments

Comments
 (0)