diff --git a/includes/dart-integrations/dio.mdx b/includes/dart-integrations/dio.mdx index f0e161c09b29ef..8d4fc35fdcceba 100644 --- a/includes/dart-integrations/dio.mdx +++ b/includes/dart-integrations/dio.mdx @@ -22,26 +22,23 @@ dependencies: ## Configure -Configuration should happen as early as possible in your application's lifecycle. - +To instrument Dio with Sentry, call `addSentry()` on your Dio instance as the very last step. +Perform any other configurations such as adding interceptors, transformers, or a custom HTTP client adapter before calling `addSentry()`. ```dart import 'package:sentry_dio/sentry_dio.dart'; -import 'package:sentry/sentry.dart'; - -Future main() async { - await Sentry.init( - (options) { - options.dsn = '___PUBLIC_DSN___'; - }, - appRunner: initApp, // Init your App. - ); -} +import 'package:dio/dio.dart'; +// 1. Create your Dio instance final dio = Dio(); -// This *must* be the last initialization step of the Dio setup. -dio.addSentry(...); +// 2. (Optional) Customize Dio as needed +// dio.transformer = ExampleTransformer(); +// dio.httpClientAdapter = ExampleHttpClientAdapter(); +// dio.interceptors.add(ExampleInterceptor()); + +// 3. Add Sentry – always LAST +dio.addSentry(); ``` ## Reporting Bad HTTP Requests as Errors @@ -50,6 +47,7 @@ The `Interceptors` can also catch exceptions that may occur during requests — ```dart import 'package:sentry_dio/sentry_dio.dart'; +import 'package:dio/dio.dart'; final dio = Dio(); @@ -134,24 +132,13 @@ Before starting, ensure: 1. The Sentry Flutter SDK is initialized. Learn more [here](/platforms/dart/guides/flutter/#configure). 2. Tracing is set up. Learn more [here](/platforms/dart/guides/flutter/tracing/). -### Configure - -Call `addSentry()` on your instance of `Dio: - -```dart -import 'package:sentry_dio/sentry_dio.dart'; - -final dio = Dio(); - -dio.addSentry(); -``` - ### Verify #### 1. Execute the Code ```dart import 'package:sentry_dio/sentry_dio.dart'; +import 'package:dio/dio.dart'; Future makeWebRequestWithDio() async { final dio = Dio(); diff --git a/platform-includes/user-feedback/sdk-api-example/dart.flutter.mdx b/platform-includes/user-feedback/sdk-api-example/dart.flutter.mdx index 5de2897512b304..2ce6b88152cb4c 100644 --- a/platform-includes/user-feedback/sdk-api-example/dart.flutter.mdx +++ b/platform-includes/user-feedback/sdk-api-example/dart.flutter.mdx @@ -10,7 +10,7 @@ await SentryFlutter.init((options) { }); // Option 2: Retrieving SentryId from the method capturing the event -SentryId sentryId = Sentry.captureMessage("My message"); +SentryId sentryId = await Sentry.captureMessage("My message"); // Option 3: Retrieving SentryId from the beforeSend callback SentryId sentryId = Sentry.lastEventId; diff --git a/platform-includes/user-feedback/sdk-api-example/dart.mdx b/platform-includes/user-feedback/sdk-api-example/dart.mdx index 755c2ec54acc6f..a665de6eac94dd 100644 --- a/platform-includes/user-feedback/sdk-api-example/dart.mdx +++ b/platform-includes/user-feedback/sdk-api-example/dart.mdx @@ -10,7 +10,7 @@ await Sentry.init((options) { }); // Option 2: Retrieving SentryId from the method capturing the event -SentryId sentryId = Sentry.captureMessage("My message"); +SentryId sentryId = await Sentry.captureMessage("My message"); // Option 3: Retrieving SentryId from the beforeSend callback SentryId sentryId = Sentry.lastEventId;