Flutter
Sentry's Flutter SDK enables automatic reporting of errors and performance data in your application.
On this page, we get you up and running with Sentry's Flutter SDK.
If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
Sentry captures data by using an SDK within your application's runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.
To install, run @sentry/wizard
:
brew install getsentry/tools/sentry-wizard && sentry-wizard -i flutter
Sentry Wizard will patch your project accordingly, though you can set up manually if you prefer. You only need to patch the project once. Then you can add the patched files to your version control system.
The following tasks will be performed by the Sentry Wizard
Configuration should happen as early as possible in your application's lifecycle.
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';
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1.0;
// The sampling rate for profiling is relative to tracesSampleRate
// Setting to 1.0 will profile 100% of sampled transactions:
// Note: Profiling alpha is available for iOS and macOS since SDK version 7.12.0
options.profilesSampleRate = 1.0;
// Adds request headers and IP for users,
// visit: https://docs.sentry.io/platforms/flutter/data-management/data-collected/ for more info
options.sendDefaultPii = true;
},
appRunner: () => runApp(
SentryWidget(
child: MyApp(),
),
),
);
// you can also configure SENTRY_DSN, SENTRY_RELEASE, SENTRY_DIST, and
// SENTRY_ENVIRONMENT via Dart environment variable (--dart-define)
}
Verify that your app is sending events to Sentry by adding the following snippet, which includes an intentional error. You should see the error reported in Sentry within a few minutes.
import 'package:sentry/sentry.dart';
try {
throw Exception('Sentry Test Exception');
} catch (exception, stackTrace) {
await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
}
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").