Skip to content

Commit bf62aa8

Browse files
feat(dart): Update dio and http integrations to include failedRequestTargets option (#15300)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Closes #15264 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Alex Krawiec <alex.krawiec@sentry.io>
1 parent ffb1d62 commit bf62aa8

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

includes/dart-integrations/dio.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,54 @@ await Sentry.init((options) {
6767
});
6868
```
6969

70+
### Failed Request Status Codes
71+
72+
You can customize which status codes should be considered failed requests by setting the `failedRequestStatusCodes` option when calling `addSentry()`.
73+
74+
```dart
75+
import 'package:sentry_dio/sentry_dio.dart';
76+
77+
final dio = Dio();
78+
79+
dio.addSentry(
80+
failedRequestStatusCodes: [
81+
SentryStatusCode.range(400, 404), // Capture 400-404
82+
SentryStatusCode(500), // Capture 500
83+
],
84+
);
85+
```
86+
87+
**Default Behavior:**
88+
89+
By default, `failedRequestStatusCodes` is set to `[SentryStatusCode.range(500, 599)]`, which captures server errors (status codes 500-599).
90+
91+
### Failed Request Targets
92+
93+
To control which URLs should have failed requests captured, use the `failedRequestTargets` option. This is useful when you only want to capture errors from specific APIs or domains.
94+
95+
The SDK will only capture HTTP client errors if the request URL matches one of the provided targets. Targets can be:
96+
97+
- Strings that appear anywhere in the URL
98+
- Regular expression patterns
99+
100+
```dart
101+
import 'package:sentry_dio/sentry_dio.dart';
102+
103+
final dio = Dio();
104+
105+
// Capture failed requests only from specific domains
106+
dio.addSentry(
107+
failedRequestTargets: [
108+
'api.example.com', // Matches any URL containing this string
109+
'myapi.com', // Another domain to track
110+
],
111+
);
112+
```
113+
114+
**Default Behavior:**
115+
116+
By default, `failedRequestTargets` is set to `['.*']`, which matches all URLs. This means all failed requests are captured (subject to `failedRequestStatusCodes`).
117+
70118
## Tracing for HTTP Requests
71119

72120
The Dio integration also provides insight into tracing for your HTTP requests done with Dio.

includes/dart-integrations/http-integration.mdx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,67 @@ try {
115115
}
116116
```
117117

118+
### Failed Request Status Codes
119+
120+
You can customize which status codes should be considered failed requests by setting the `failedRequestStatusCodes` option when calling `SentryHttpClient()`.
121+
122+
```dart
123+
import 'package:sentry/sentry.dart';
124+
125+
var client = SentryHttpClient(
126+
failedRequestStatusCodes: [
127+
SentryStatusCode.range(400, 404), // Capture 400-404
128+
SentryStatusCode(500), // Capture 500
129+
],
130+
);
131+
132+
try {
133+
var uriResponse = await client.post('https://example.com/whatsit/create',
134+
body: {'name': 'doodle', 'color': 'blue'});
135+
print(await client.get(uriResponse.bodyFields['uri']));
136+
} finally {
137+
client.close();
138+
}
139+
```
140+
141+
**Default Behavior:**
142+
143+
By default, `failedRequestStatusCodes` is set to `[SentryStatusCode.range(500, 599)]`, which captures server errors (status codes 500-599).
144+
145+
### Failed Request Targets
146+
147+
To control which URLs should have failed requests captured, use the `failedRequestTargets` option. This is useful when you only want to capture errors from specific APIs or domains.
148+
149+
The SDK will only capture HTTP client errors if the request URL matches one of the provided targets. Targets can be:
150+
151+
- Strings that appear anywhere in the URL
152+
- Regular expression patterns
153+
154+
```dart
155+
import 'package:sentry/sentry.dart';
156+
157+
// Capture failed requests only from specific domains
158+
var client = SentryHttpClient(
159+
failedRequestTargets: [
160+
'api.example.com', // Matches any URL containing this string
161+
'myapi.com', // Another domain to track
162+
],
163+
);
164+
165+
try {
166+
var uriResponse = await client.post('https://api.example.com/whatsit/create',
167+
body: {'name': 'doodle', 'color': 'blue'});
168+
print(await client.get(uriResponse.bodyFields['uri']));
169+
} finally {
170+
client.close();
171+
}
172+
```
173+
174+
**Default Behavior:**
175+
176+
By default, `failedRequestTargets` is set to `['.*']`, which matches all URLs. This means all failed requests are captured (subject to `failedRequestStatusCodes`).
177+
178+
118179
## Tracing for HTTP Requests
119180

120181
<Alert>

0 commit comments

Comments
 (0)