Dio Integration
The sentry_dio
library provides Dio support for Sentry using the HttpClientAdapter. It is able to collect breadcrumbs, run performance monitoring for HTTP requests, and capture events for failed requests.
The source can be found on GitHub.
Install
To add the Dio integration, add the sentry_dio
dependency.
pubspec.yaml
Copied
dependencies:
sentry: ^7.10.1
sentry_dio: ^7.10.1
dio: ^4.0.0
Configure
Configuration should happen as early as possible in your application's lifecycle.
Copied
import 'package:sentry_dio/sentry_dio.dart';
import 'package:sentry/sentry.dart';
Future<void> main() async {
await Sentry.init(
(options) {
options.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0';
},
appRunner: initApp, // Init your App.
);
}
final dio = Dio();
// This *must* be the last initialization step of the Dio setup.
dio.addSentry(...);
Reporting Bad HTTP Requests as Errors
The Interceptors
can also catch exceptions that may occur during requests — for example DioError.
Copied
import 'package:sentry_dio/sentry_dio.dart';
final dio = Dio();
dio.addSentry();
final response = await dio.get<String>('https://wrong-url.dev/');
This is an opt-out feature. The following example shows how to disable it:
Copied
import 'package:sentry/sentry.dart';
Future<void> main() async {
await Sentry.init(
(options) {
options.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0';
options.captureFailedRequests = false;
},
appRunner: initApp, // Init your App.
);
}
Performance Monitoring for HTTP Requests
Capturing transactions requires that you first set up performance monitoring if you haven't already.
The Dio integration starts a span out of the active span bound to the scope for each HTTP request.
Copied
import 'package:sentry_dio/sentry_dio.dart';
final dio = Dio();
dio.addSentry();
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
Suggest an edit to this page | Contribute to Docs | Report a problem
🎉 Thank you for your feedback! 🙌
- Package:
- pub:sentry
- Version:
- 7.10.1
- Repository:
- https://github.com/getsentry/sentry-dart