Skip to content

Commit 2004f78

Browse files
authored
docs(flutter): Document beforeCapture function customization (#12190)
1 parent 4fde9bf commit 2004f78

File tree

2 files changed

+51
-1
lines changed
  • docs/platforms/flutter/enriching-events/viewhierarchy
  • platform-includes/enriching-events/attach-screenshots

2 files changed

+51
-1
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ View hierarchy debugging is an opt-in feature. You can enable it as shown below:
2121

2222
<PlatformContent includePath="enriching-events/attach-viewhierarchy" />
2323

24+
### Customize View Hierarchy Capturing
25+
26+
<Note>
27+
28+
Requires SDK version `8.13.0` or higher.
29+
30+
</Note>
31+
32+
Capturing view hierarchies on Flutter is limited to once every 2 seconds by default to minimize performance impact. While this debounce interval is fixed, you can override individual capture decisions by implementing the `beforeCaptureViewHierarchy` option in your `SentryFlutterOptions`.
33+
34+
The `beforeCaptureViewHierarchy` option allows you to customize behavior based on event data so you can decide when to capture view hierarchy and when not to. For example, you can decide to only capture view hierarchy for fatal events:
35+
36+
```flutter {2-9}
37+
await SentryFlutter.init((options) {
38+
options.beforeCaptureViewHierarchy = (event, hint, debounce) async {
39+
// If debounce is active, skip capturing
40+
if (debounce) {
41+
return false;
42+
}
43+
// Capture if it's a fatal event
44+
return event.level == SentryLevel.fatal;
45+
};
46+
});
47+
```
48+
2449
## Viewing View Hierarchy Attachments
2550

2651
View hierarchies appear in the "Attachments" tab, where you can view all attachments, as well as associated events. Click the event ID to open the [Issue Details](/product/issues/issue-details) page of that specific event.

platform-includes/enriching-events/attach-screenshots/flutter.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ await SentryFlutter.init(
1313
);
1414
```
1515

16+
### Customize Screenshot Capturing
17+
18+
<Note>
19+
20+
Requires SDK version `8.11.0` or higher.
21+
22+
</Note>
23+
24+
Capturing screenshots on Flutter is limited to once every 2 seconds by default to minimize performance impact. While this debounce interval is fixed, you can override individual capture decisions by implementing the `beforeCaptureScreenshot` option in your `SentryFlutterOptions`.
25+
26+
The `BeforeCaptureCallback` also allows you to customize the behavior based on event data, so you can decide when to capture a screenshot and when not to. For example, you can decide to only capture screenshots of fatal events:
27+
28+
```flutter {2-9}
29+
await SentryFlutter.init((options) {
30+
options.beforeCaptureScreenshot = (event, hint, debounce) async {
31+
// If debounce is active, skip capturing
32+
if (debounce) {
33+
return false;
34+
}
35+
// Capture if it's a fatal event
36+
return event.level == SentryLevel.fatal;
37+
};
38+
});
39+
```
40+
1641
## Redact Screenshots via `masking`
1742

1843
The masking feature is by default disabled for Screenshots. To enable masking, use the `options.experimental.privacy` parameter.
@@ -26,7 +51,7 @@ The masking feature is by default disabled for Screenshots. To enable masking, u
2651

2752
## Filtering Screenshots
2853

29-
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.
54+
You can filter your screenshots by using the `beforeCaptureScreenshot` callback, which is called before attaching a screenshot to an event. By default, the callback returns `true` which means that all screenshots are attached.
3055

3156
If the callback returns `false`, the screenshot will not be attached.
3257

0 commit comments

Comments
 (0)