Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 13 additions & 26 deletions includes/dart-integrations/dio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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
Expand All @@ -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();

Expand Down Expand Up @@ -86,24 +84,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<void> makeWebRequestWithDio() async {
final dio = Dio();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion platform-includes/user-feedback/sdk-api-example/dart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down