Screenshots
Sentry makes it possible to automatically take a screenshot and include it as an attachment when a user experiences an error, an exception or a crash.
This feature is only available for SDKs with a user interface, like the ones for mobile and desktop applications. It's also limited by whether taking a screenshot is possible or not. For example, in some environments, like native iOS, taking a screenshot requires the UI thread, which often isn't available in the event of a crash. Another example where a screenshot might not be available is when the event happens before the screen starts to load. So inherently, this feature is a best effort solution.
Because screenshots may contain PII, they are an opt-in feature. You can enable screenshots as shown below:
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0';
options.attachScreenshot = true;
},
appRunner: () => runApp(
// Wrap your app widget with the [SentryWidget] widget.
SentryWidget(
child: MyApp(),
),
),
);
}
You can filter your screenshots by using the beforeScreenshot
callback. It is called before taking a screenshot and if the callback returns false
, the screenshot will not be attached.
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0';
options.attachScreenshot = true;
options.beforeScreenshot = (event, {hint}) {
// Return false if you don't want to attach the screenshot based on some condition.
return true;
};
},
appRunner: () => runApp(
// Wrap your app widget with the [SentryWidget] widget.
SentryWidget(
child: MyApp(),
),
),
);
}
If one is available, you'll see a thumbnail of the screenshot when you click on a specific issue from the Issues page.
Once you've clicked on the event ID of a specific issue, you'll be able to see an overview of all the attachments as well as associated events in the "Attachments" tab.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- pub:sentry_flutter
- Version:
- 7.20.0
- Repository:
- https://github.com/getsentry/sentry-dart
- API Documentation:
- https://pub.dev/documentation/sentry_flutter/latest/