From 475c76de74a0b2bb8d75dd82fc20403154c488fc Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 23 Oct 2025 13:00:22 +0200 Subject: [PATCH] Update dio and http integrations --- includes/dart-integrations/dio.mdx | 48 +++++++++++++++ .../dart-integrations/http-integration.mdx | 61 +++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/includes/dart-integrations/dio.mdx b/includes/dart-integrations/dio.mdx index e6f85f0e821c1..0fa6de6150bf9 100644 --- a/includes/dart-integrations/dio.mdx +++ b/includes/dart-integrations/dio.mdx @@ -67,6 +67,54 @@ await Sentry.init((options) { }); ``` +### Failed Request Status Codes + +You can customize which status codes should be considered as failed requests by setting the `failedRequestStatusCodes` option when calling `addSentry()`. + +```dart +import 'package:sentry_dio/sentry_dio.dart'; + +final dio = Dio(); + +dio.addSentry( + failedRequestStatusCodes: [ + SentryStatusCode.range(400, 404), // Capture 400-404 + SentryStatusCode(500), // Capture 500 + ], +); +``` + +**Default Behavior:** + +By default, `failedRequestStatusCodes` is set to `[SentryStatusCode.range(500, 599)]`, which captures server errors (status codes 500-599). + +### Failed Request Targets + +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. + +The SDK will only capture HTTP client errors if the request URL matches one of the provided targets. Targets can be: + +- Strings that appear anywhere in the URL +- Regular expression patterns + +```dart +import 'package:sentry_dio/sentry_dio.dart'; + +final dio = Dio(); + +// Capture failed requests only from specific domains +dio.addSentry( + failedRequestTargets: [ + 'api.example.com', // Matches any URL containing this string + 'myapi.com', // Another domain to track + ], +); +``` + +**Default Behavior:** + +By default, `failedRequestTargets` is set to `['.*']`, which matches all URLs. This means all failed requests are captured (subject to `failedRequestStatusCodes`). + ## Tracing for HTTP Requests The Dio integration also provides insight into tracing for your HTTP requests done with Dio. diff --git a/includes/dart-integrations/http-integration.mdx b/includes/dart-integrations/http-integration.mdx index f240ba2ef70bd..96fc417def50a 100644 --- a/includes/dart-integrations/http-integration.mdx +++ b/includes/dart-integrations/http-integration.mdx @@ -115,6 +115,67 @@ try { } ``` +### Failed Request Status Codes + +You can customize which status codes should be considered as failed requests by setting the `failedRequestStatusCodes` option when calling `SentryHttpClient()`. + +```dart +import 'package:sentry/sentry.dart'; + +var client = SentryHttpClient( + failedRequestStatusCodes: [ + SentryStatusCode.range(400, 404), // Capture 400-404 + SentryStatusCode(500), // Capture 500 + ], +); + +try { + var uriResponse = await client.post('https://example.com/whatsit/create', + body: {'name': 'doodle', 'color': 'blue'}); + print(await client.get(uriResponse.bodyFields['uri'])); +} finally { + client.close(); +} +``` + +**Default Behavior:** + +By default, `failedRequestStatusCodes` is set to `[SentryStatusCode.range(500, 599)]`, which captures server errors (status codes 500-599). + +### Failed Request Targets + +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. + +The SDK will only capture HTTP client errors if the request URL matches one of the provided targets. Targets can be: + +- Strings that appear anywhere in the URL +- Regular expression patterns + +```dart +import 'package:sentry/sentry.dart'; + +// Capture failed requests only from specific domains +var client = SentryHttpClient( + failedRequestTargets: [ + 'api.example.com', // Matches any URL containing this string + 'myapi.com', // Another domain to track + ], +); + +try { + var uriResponse = await client.post('https://api.example.com/whatsit/create', + body: {'name': 'doodle', 'color': 'blue'}); + print(await client.get(uriResponse.bodyFields['uri'])); +} finally { + client.close(); +} +``` + +**Default Behavior:** + +By default, `failedRequestTargets` is set to `['.*']`, which matches all URLs. This means all failed requests are captured (subject to `failedRequestStatusCodes`). + + ## Tracing for HTTP Requests