Skip to content

Commit ce079ff

Browse files
authored
Feat: Document Dio for Dart/Flutter (#4857)
1 parent bcd825d commit ce079ff

File tree

6 files changed

+114
-11
lines changed

6 files changed

+114
-11
lines changed

src/includes/getting-started-primer/dart.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ Sentry's Dart SDK enables automatic reporting of errors, messages, and exception
88

99
- Breadcrumbs automatically captured:
1010
- by the [Dart SDK](/platforms/dart/enriching-events/breadcrumbs/#automatic-breadcrumbs)
11-
- as well as `http` with the [Dart SDK](/platforms/dart/)
11+
- by the [Logging Integration](/platforms/dart/configuration/integrations/logging)
12+
- by the [Dio Integration](/platforms/dart/configuration/integrations/dio/)
1213
- [Attachments](/platforms/dart/enriching-events/attachments/) enrich your event by storing additional files, such as config or log files.
1314
- [User Feedback](/platforms/dart/enriching-events/user-feedback/) provides the ability to collect user information when an event occurs.
1415
- [Performance Monitoring](/product/performance/) creates transactions for:
1516
- [HTTP requests](/platforms/dart/configuration/integrations/http-integration/#performance-monitoring-for-http-requests)
17+
- [Dio HTTP library](/platforms/dart/configuration/integrations/dio/#performance-monitoring-for-http-requests)
1618
- [Logging Integration](/platforms/dart/configuration/integrations/logging)
19+
- [Dio Integration](/platforms/dart/configuration/integrations/dio/)

src/includes/getting-started-primer/flutter.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ Features:
1212
- Offline storage of events
1313
- Events [enriched](/platforms/flutter/enriching-events/context/) with device data
1414
- Breadcrumbs automatically captured:
15-
- by the [Flutter SDK](/platforms/flutter/enriching-events/breadcrumbs/#automatic-breadcrumbs)
15+
- by the [Dart SDK](/platforms/dart/enriching-events/breadcrumbs/#automatic-breadcrumbs)
16+
- by the [Flutter SDK](/platforms/flutter/enriching-events/breadcrumbs/#automatic-breadcrumbs)
1617
- via the Native SDKs [Automatic Breadcrumbs for Android](/platforms/android/enriching-events/breadcrumbs/#automatic-breadcrumbs) and [Automatic Breadcrumbs for iOS](/platforms/apple/configuration/integrations/default/#sentryautobreadcrumbtrackingintegration)
17-
- as well as `http` with the [Dart SDK](/platforms/dart/)
18+
- by the [Logging Integration](/platforms/dart/configuration/integrations/logging)
19+
- by the [Dio Integration](/platforms/dart/configuration/integrations/dio/)
1820
- [Release Health](/product/releases/health/) tracks crash free users and sessions
1921
- [Attachments](/platforms/flutter/enriching-events/attachments/) enrich your event by storing additional files, such as config or log files.
2022
- [User Feedback](/platforms/flutter/enriching-events/user-feedback/) provides the ability to collect user information when an event occurs.
2123
- [Performance Monitoring](/product/performance/) creates transactions for:
2224
- [HTTP requests](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#httpclient-library-instrumentation)
2325
- [Routing Instumentation](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#routing-instumentation)
26+
- [Dio HTTP library](/platforms/dart/configuration/integrations/dio/#performance-monitoring-for-http-requests)
2427
- [Cold and warm app start](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#app-start-instrumentation)
2528
- [Slow and frozen frames](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#slow-and-frozen-frames)
2629
- [Logging Integration](/platforms/dart/configuration/integrations/logging)

src/platforms/dart/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ The `http.Client` instrumentation, once added the `SentryHttpClient` and enabled
1818

1919
The span finishes once the request has been executed. The span `status` depends on either the HTTP Response `code` or `SpanStatus.internalError()` if the `code` does not match any of Sentry's `SpanStatus`.
2020

21-
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and SentryEvent will be linked when viewing it on the **Issue Details** page in sentry.io.
21+
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in sentry.io.
2222

2323
For more information see our [SentryHttpClient integration](/platforms/dart/configuration/integrations/http-integration/#performance-monitoring-for-http-requests).
24+
25+
### Dio HTTP Library Instrumentation
26+
27+
The Dio instrumentation starts a span out of the active span bound to the scope for each HTTP request. The SDK sets the span `operation` to `http.client` and the `description` to request `$method $URL`. For example, `GET https://sentry.io`.
28+
29+
The span finishes once the request has been executed. The span `status` depends on either the HTTP response `code` or `SpanStatus.internalError()` if the `code` does not match any of Sentry's `SpanStatus` options.
30+
31+
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in [sentry.io](https://sentry.io).
32+
33+
Learn more in our [Dio integration documentation](/platforms/dart/configuration/integrations/dio/#performance-monitoring-for-http-requests).
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Dio Integration
3+
sidebar_order: 4
4+
description: "Learn more about the Sentry Dio integration for the Dart SDK."
5+
---
6+
7+
The `sentry_dio` library provides [Dio](https://pub.dev/packages/dio) support for Sentry using the [HttpClientAdapter](https://pub.dev/documentation/dio/latest/dio/HttpClientAdapter-class.html). It is able to collect breadcrumbs, run performance monitoring for HTTP requests, and capture events for failed requests.
8+
9+
The source can be found [on GitHub](https://github.com/getsentry/sentry-dart/tree/main/dio/).
10+
11+
<Note>
12+
13+
This is an experimental feature. Experimental features are still a work-in-progress and may have bugs. We recognize the irony.
14+
15+
</Note>
16+
17+
## Install
18+
19+
To add the Dio integration, add the `sentry_dio` dependency.
20+
21+
```yml {filename:pubspec.yaml}
22+
dependencies:
23+
sentry: ^{{ packages.version('sentry.dart', '6.4.0') }}
24+
sentry_dio: ^{{ packages.version('sentry.dart.dio', '6.4.0') }}
25+
dio: ^4.0.0
26+
```
27+
28+
## Configure
29+
30+
Configuration should happen as early as possible in your application's lifecycle.
31+
32+
```dart
33+
import 'package:sentry_dio/sentry_dio.dart';
34+
import 'package:sentry/sentry.dart';
35+
36+
Future<void> main() async {
37+
await Sentry.init(
38+
(options) {
39+
options.dsn = '___PUBLIC_DSN___';
40+
},
41+
appRunner: initApp, // Init your App.
42+
);
43+
}
44+
45+
final dio = Dio();
46+
47+
// This *must* be the last initialization step of the Dio setup.
48+
dio.addSentry(...);
49+
```
50+
51+
## Reporting Bad HTTP Requests as Errors
52+
53+
The `Interceptors` can also catch exceptions that may occur during requests — for example [DioError](https://pub.dev/documentation/dio/latest/dio/DioError-class.html).
54+
This is currently an opt-in feature. The following example shows how to enable it.
55+
56+
```dart
57+
import 'package:sentry_dio/sentry_dio.dart';
58+
59+
final dio = Dio();
60+
61+
dio.addSentry(captureFailedRequests: true);
62+
63+
final response = await dio.get<String>('https://wrong-url.dev/');
64+
```
65+
66+
## Performance Monitoring for HTTP Requests
67+
68+
<Note>
69+
70+
Capturing transactions requires that you first <PlatformLink to="/performance/">set up performance monitoring</PlatformLink> if you haven't already.
71+
72+
</Note>
73+
74+
The Dio integration starts a span out of the active span bound to the scope for each HTTP request.
75+
This is currently enabled by default. The following example shows how to disable it.
76+
77+
```dart
78+
import 'package:sentry_dio/sentry_dio.dart';
79+
80+
final dio = Dio();
81+
82+
dio.addSentry(networkTracing: false);
83+
```

src/platforms/dart/configuration/integrations/http-integration.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ redirect_from:
66
description: "Learn more about the Sentry HTTP integration for the Dart SDK."
77
---
88

9-
<Note>
10-
11-
The minimum required Dart SDK version is `2.12.0`.
12-
13-
</Note>
14-
159
## Reporting Bad HTTP Requests as Errors
1610

1711
The `SentryHttpClient` can also catch exceptions that may occur during requests — for example [`SocketException`](https://api.dart.dev/stable/2.13.4/dart-io/SocketException-class.html).

src/platforms/flutter/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ The `http.Client` instrumentation, once added the `SentryHttpClient` and enabled
1818

1919
The span finishes once the request has been executed. The span `status` depends on either the HTTP Response `code` or `SpanStatus.internalError()` if the `code` does not match any of Sentry's `SpanStatus`.
2020

21-
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and SentryEvent will be linked when viewing it on the **Issue Details** page in sentry.io.
21+
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in sentry.io.
2222

2323
For more information see our [SentryHttpClient integration](/platforms/dart/configuration/integrations/http-integration/#performance-monitoring-for-http-requests).
2424

25+
### Dio HTTP Library Instrumentation
26+
27+
The Dio instrumentation starts a span out of the active span bound to the scope for each HTTP request. The SDK sets the span `operation` to `http.client` and the `description` to request `$method $URL`. For example, `GET https://sentry.io`.
28+
29+
The span finishes once the request has been executed. The span `status` depends on either the HTTP response `code` or `SpanStatus.internalError()` if the `code` does not match any of Sentry's `SpanStatus` options.
30+
31+
When the HTTP request throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in [sentry.io](https://sentry.io).
32+
33+
Learn more in our [Dio integration documentation](/platforms/dart/configuration/integrations/dio/#performance-monitoring-for-http-requests).
34+
2535
### Routing Instumentation
2636

2737
Automatic routing instrumentation can be enabled by adding an instance of `SentryNavigationObserver` to your application's `navigatorObservers`. Transactions are started automatically when routing to new pages in your application.

0 commit comments

Comments
 (0)