Reporting Crashes for Flutter
Covered here are APIs relevant to crash reporting for your Flutter app.
Privacy Policy
It is highly recommended to mention in your privacy policy that you may be collecting logging data in order to assist with troubleshooting crashes.
With Instabug Crash Reporting there are two ways to have your application report a crash, either automatically or manually. After the crash is sent to your dashboard, you can sort and filter for specific crashes easily.
Automatic Crash Reporting
If you enable Crash Reporting, crashes will automatically be reported to and viewable from the crashes page of your Instabug dashboard.
You'll also see the trends covering the previous 7 days, including:
- Crash-free sessions: the percentage of sessions that ran and concluded without any fatal errors.
- Crash-free users: the percentage of users that haven't encountered any fatal errors.
- Crashing sessions: the number of sessions that ran and concluded with a fatal error.
- Affected users: the number of unique users who had one or more sessions that ended with a fatal error.
- Total number of occurrences: by hovering on it, you’ll get a breakdown of the number of fatal sessions, the number of OOM sessions, the number of ANR sessions, and the number of non-fatal sessions.
If there is a sharp decline in the crash-free sessions rate, an email will be sent to notify you.
Warning
Crash reporting will not function correctly if the device is connected to Xcode. When it is, Xcode catches all the exceptions and they will not be sent to your dashboard.
Setting Up Automatic Crash Reporting
You'll need to follow the below step in order to turn on automatic crash reporting in our Flutter SDK.
Replace void main() => runApp(MyApp());
with the following snippet:
void main() {
runZonedGuarded(() {
WidgetsFlutterBinding.ensureInitialized();
Instabug.init(
token: 'APP_TOKEN',
invocationEvents: [InvocationEvent.floatingButton],
);
FlutterError.onError = (FlutterErrorDetails details) {
Zone.current.handleUncaughtError(details.exception, details.stack!);
};
runApp(MyApp());
}, CrashReporting.reportCrash);
}
Release Mode
Crashes will only be reported in release mode and not in debug mode.
Manual Crash Reporting
You can offer your users Instabug Bug Reporting to report bugs. However, you can use the following method and API to manually report any error or exception that you handle in your code and assign it a severity level.
Report Exception
To report exceptions manually, use the following method.
CrashReporting.reportHandledCrash(error, stackTrace);
Min Required SDK version
Customizing crash level and custom grouping is supported starting Flutter SDK v13.1.1.
Add Level to Exception
You can set different severity levels for manually reported exceptions using the following API:
try {
throw Exception();
} catch (exception, stacktrace) {
CrashReporting.reportHandledCrash(exception, stacktrace,
level: NonFatalExceptionLevel.critical);
}
Here are the different severity levels available. In case no level is indicated, the default level would be error.
NonFatalExceptionLevel.info;
NonFatalExceptionLevel.error;
NonFatalExceptionLevel.warning;
NonFatalExceptionLevel.critical;
Grouping
When an already existing crash occurs once more for any user, that crash is reported as an occurrence in the original entry. However, in order to calculate whether a crash already exists and needs to be grouped, Instabug generates a fingerprint based on attributes used in the grouping logic.
The default Instabug grouping algorithm uses a mix of the exception and stack trace information. In some cases, you might want to change how the issues are grouped together using fingerprints.
Custom Fingerprinting
Overriding the default grouping
Please note that using custom fingerprinting will override Instabug's default grouping by sending a fingerprint string.
In the event that you'd like to report the exception manually with a custom grouping fingerprint in mind, you can use the below APIs to do just that.
try {
throw Exception();
} catch (exception, stacktrace) {
CrashReporting.reportHandledCrash(exception, stacktrace,
userAttributes: userAttributeMap,
fingerprint: 'grouping fingerprint',
level: NonFatalExceptionLevel.info);
}
Crashes List
This section contains a list of all the crashes that have been reported by your application. The title of each crash is usually the most significant line in the stack trace.
Next to each crash in the list, you can find the following details, all of which can be used to sort the crashes:
- Occurrences: The number of times this crash has occurred and a bar graph representing its occurrences over the past seven days.
- Users: The number of users affected by this crash.
- Min ver.: The oldest app version that was affected by this crash.
- Max ver.: The latest app version that was affected by this crash.
- Last seen: The last time an occurrence of this crash was reported.
You can then filter for crashes that match any of the following criteria:
- App version
- Date
- Device
- OS
- User attributes
- Type
- Status
- Assignee
- Team
- Tags
- Current view
- Experiments
Updated 5 months ago