Sentry SDK for Flutter
package | build | pub | likes | popularity | pub points |
---|---|---|---|---|---|
sentry_flutter |
This package includes support to native crashes through Sentry's native SDKs: (Android and iOS). It will capture errors in the native layer, including (Java/Kotlin/C/C++ for Android and Objective-C/Swift for iOS).
Usage
-
Sign up for a Sentry.io account and get a DSN at http://sentry.io.
-
Follow the installing instructions on pub.dev.
-
Initialize the Sentry SDK using the DSN issued by Sentry.io:
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://example@sentry.io/add-your-dsn-here';
},
// Init your App.
appRunner: () => runApp(MyApp()),
);
}
Or, if you want to run your app in your own error zone runZonedGuarded:
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://example@sentry.io/add-your-dsn-here';
},
);
runApp(MyApp());
}
Tracking navigation events
In order to track navigation events you have to add the
SentryNavigationObserver
to your MaterialApp
, WidgetsApp
or CupertinoApp
.
import 'package:flutter/material.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
// ...
MaterialApp(
navigatorObservers: [
SentryNavigatorObserver(),
],
// other parameters
)
// ...
For a more throughout example see the example.
Known limitations
- Flutter
split-debug-info
andobfuscate
flag aren't supported on iOS yet, but only on Android, if this feature is enabled, Dart stack traces are not human readable - If you enable the
split-debug-info
feature, you must upload the Debug Symbols manually.
Uploading Debug Symbols (Android and iOS)
- iOS dSYM files
- Android NDK, You must to do it manually. Do not use the
uploadNativeSymbols
flag from the Sentry Gradle Plugin, because it's not yet supported. - Android Proguard/R8 mapping file
- Source maps for Flutter Web
Tips for catching errors
- Use a
try/catch
block. - Use a
catchError
block forFutures
, examples on dart.dev. - The SDK already runs your
callback
on an error handler, e.g. using runZonedGuarded, events caught by therunZonedGuarded
are captured automatically. - Flutter-specific errors (such as layout failures) are captured automatically.
- Current Isolate errors which is the equivalent of a main or UI thread, are captured automatically (Only for non-Web Apps).
- For your own
Isolates
, add an Error Listener and callSentry.captureException
.