From 6b23313704eaa78e419fd2ce848b41e0bf576394 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Mon, 31 Oct 2022 11:18:04 +0100 Subject: [PATCH 01/10] HTTP Client errors docs for iOS --- .../getting-started-primer/android.mdx | 1 + .../getting-started-primer/apple.mdx | 1 + .../configuration/http-client-errors.mdx | 104 ++++++++++++++++++ .../apple/common/configuration/swizzling.mdx | 2 + .../common/configuration/options.mdx | 12 ++ 5 files changed, 120 insertions(+) create mode 100644 src/platforms/apple/common/configuration/http-client-errors.mdx diff --git a/src/platform-includes/getting-started-primer/android.mdx b/src/platform-includes/getting-started-primer/android.mdx index 0cbbae89648f7..fd30545461574 100644 --- a/src/platform-includes/getting-started-primer/android.mdx +++ b/src/platform-includes/getting-started-primer/android.mdx @@ -38,6 +38,7 @@ The SDK builds a crash report that persists to disk and tries to send the report - Apollo request spans with [Apollo Integration](/platforms/android/configuration/integrations/apollo/) - Distributed tracing through [OkHttp](/platforms/android/configuration/integrations/okhttp/) and [Apollo](/platforms/android/configuration/integrations/apollo/) integrations - [Application Not Responding (ANR)](/platforms/android/configuration/app-not-respond/) reported if the application is blocked for more than five seconds +- [HTTP Client Errors](/platforms/android/configuration/integrations/okhttp/#http-client-errors) - Code samples provided in both Kotlin and Java as the Android SDK uses both languages - We provide a [sample application](https://github.com/getsentry/sentry-java/tree/master/sentry-samples/sentry-samples-android) for our Android users - Our [video tutorial](/platforms/android/android-video/) visually demonstrates how to set up our SDK diff --git a/src/platform-includes/getting-started-primer/apple.mdx b/src/platform-includes/getting-started-primer/apple.mdx index 214af6d7612dc..baf47327a4d51 100644 --- a/src/platform-includes/getting-started-primer/apple.mdx +++ b/src/platform-includes/getting-started-primer/apple.mdx @@ -11,6 +11,7 @@ - Error messages of fatalError, assert, and precondition - [App Hang Detection](/platforms/apple/configuration/app-hangs/) - [Out of memory](/platforms/apple/configuration/out-of-memory/) + - [HTTP Client Errors](/platforms/apple/configuration/http-client-errors/) - Start-up crashes. The SDK init waits synchronously for up to 5 seconds to flush out events if the app crashes within 2 seconds after the SDK init. - Events [enriched](/platforms/apple/enriching-events/context/) with device data - Offline caching when a device is unable to connect; we send a report once we receive another event diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx new file mode 100644 index 0000000000000..671161e76d6a3 --- /dev/null +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -0,0 +1,104 @@ +--- +title: HTTP Client Errors +sidebar_order: 13 +description: "This feature, once enabled, automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry" +--- + +This feature, once enabled, automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. The error event will contain the `request` and `response` data, such as `url`, `status_code`, and so on. + +This feature is opt-in and can be enabled by setting the `enableCaptureFailedRequests` option to `true`: + +```swift {tabTitle:Swift} +import Sentry + +SentrySDK.start { options in + options.dsn = "___PUBLIC_DSN___" + options.enableCaptureFailedRequests = true +} +``` + +```objc {tabTitle:Objective-C} +@import Sentry; + +[SentrySDK startWithConfigureOptions:^(SentryOptions *options) { + options.dsn = @"___PUBLIC_DSN___"; + options.enableCaptureFailedRequests = YES; +}]; +``` + +This feature requires the setting `enableSwizzling` to be enabled as well. + +By default, only HTTP client errors with a response code between `500` and `599` are captured as error events, but you can change this behavior by setting the `failedRequestStatusCodes` option: + +```swift {tabTitle:Swift} +import Sentry + +SentrySDK.start { options in + options.dsn = "___PUBLIC_DSN___" + let httpStatusCodeRange = HttpStatusCodeRange(min: 400, max: 599) + options.failedRequestStatusCodes = [ httpStatusCodeRange ] +} +``` + +```objc {tabTitle:Objective-C} +@import Sentry; + +[SentrySDK startWithConfigureOptions:^(SentryOptions *options) { + options.dsn = @"___PUBLIC_DSN___"; + SentryHttpStatusCodeRange *httpStatusCodeRange = + [[SentryHttpStatusCodeRange alloc] initWithMin:400 max:599]; + options.failedRequestStatusCodes = @[ httpStatusCodeRange ]; +}]; +``` + +HTTP client errors from every target (`.*` regular expression) are automatically captured, but you can change this behavior by setting the `failedRequestTargets` option with either a regular expression or a plain `String`. A plain string must contain at least one of the items from the list. Plain strings don't have to be full matches, meaning the URL of a request is matched when it contains a string provided through the option. + +```swift {tabTitle:Swift} +import Sentry + +SentrySDK.start { options in + options.dsn = "___PUBLIC_DSN___" + options.failedRequestTargets = [ "www.example.com" ] +} +``` + +```objc {tabTitle:Objective-C} +@import Sentry; + +[SentrySDK startWithConfigureOptions:^(SentryOptions *options) { + options.dsn = @"___PUBLIC_DSN___"; + options.failedRequestTargets = @[ @"www.example.com" ]; +}]; +``` + +Error events may contain PII data, such as `Headers` and `Cookies`, Sentry already does data scrubbing by default, but you can scrub any data before it is sent, learn more about it in the [Scrubbing Sensitive Data docs](/platforms/apple/guides/ios/data-management/sensitive-data/). + +Those events are searchable and you can set alerts on them if you use the `http.url` and `http.status_code` properties. Learn more in our full [Searchable Properties](/product/sentry-basics/search/searchable-properties/) documentation. + +### Customize or Drop the Error Event + +The captured error event can be customized or dropped with a `beforeSend`: + +```swift {tabTitle:Swift} +import Sentry + +SentrySDK.start { options in + options.dsn = "___PUBLIC_DSN___" + options.beforeSend = { event in + // modify event here or return NULL to discard the event + return event + } +} +``` + +```objc {tabTitle:Objective-C} +@import Sentry; + +[SentrySDK startWithConfigureOptions:^(SentryOptions *options) { + options.dsn = @"___PUBLIC_DSN___"; + options.beforeSend = ^SentryEvent * _Nullable(SentryEvent * _Nonnull event) { + // modify event here or return NULL to discard the event + return event; + } +}]; +``` diff --git a/src/platforms/apple/common/configuration/swizzling.mdx b/src/platforms/apple/common/configuration/swizzling.mdx index 769b9f51d2b09..489dc15e931df 100644 --- a/src/platforms/apple/common/configuration/swizzling.mdx +++ b/src/platforms/apple/common/configuration/swizzling.mdx @@ -12,6 +12,7 @@ __macOS__ - Auto instrumentation for File I/O operations - Auto instrumentation for Core Data operations - Automatically added sentry-trace header to HTTP requests for distributed tracing +- HTTP Client Errors __iOS, tvOS and Catalyst__ @@ -23,6 +24,7 @@ __iOS, tvOS and Catalyst__ - Auto instrumentation for Core Data operations - Automatically added sentry-trace header to HTTP requests for distributed tracing - User interaction transactions for UI clicks (experimental) +- HTTP Client Errors Since Cocoa 7.5.0, you can opt out of swizzling using options. When you disable swizzling, the SDK disables the features above: diff --git a/src/platforms/common/configuration/options.mdx b/src/platforms/common/configuration/options.mdx index 545f43d85aa7a..ba06c3374bbea 100644 --- a/src/platforms/common/configuration/options.mdx +++ b/src/platforms/common/configuration/options.mdx @@ -507,6 +507,18 @@ _(New in version 6.6.0)_ + + +This feature, once enabled, automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. + + + +_(New in version 7.30.0)_ + + + + + ## Integration Configuration From 0749fd1acb6aad81cfcce4235cc7442933a22cd2 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Mon, 31 Oct 2022 11:30:05 +0100 Subject: [PATCH 02/10] fix --- src/platforms/apple/common/configuration/swizzling.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/apple/common/configuration/swizzling.mdx b/src/platforms/apple/common/configuration/swizzling.mdx index 489dc15e931df..41c1f2870eef5 100644 --- a/src/platforms/apple/common/configuration/swizzling.mdx +++ b/src/platforms/apple/common/configuration/swizzling.mdx @@ -12,7 +12,7 @@ __macOS__ - Auto instrumentation for File I/O operations - Auto instrumentation for Core Data operations - Automatically added sentry-trace header to HTTP requests for distributed tracing -- HTTP Client Errors +- HTTP Client Errors __iOS, tvOS and Catalyst__ @@ -24,7 +24,7 @@ __iOS, tvOS and Catalyst__ - Auto instrumentation for Core Data operations - Automatically added sentry-trace header to HTTP requests for distributed tracing - User interaction transactions for UI clicks (experimental) -- HTTP Client Errors +- HTTP Client Errors Since Cocoa 7.5.0, you can opt out of swizzling using options. When you disable swizzling, the SDK disables the features above: From e167cf4921a1802cacd1fbb9e7010c8d9403f5de Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:45:17 +0100 Subject: [PATCH 03/10] Update src/platforms/apple/common/configuration/http-client-errors.mdx Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/apple/common/configuration/http-client-errors.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx index 671161e76d6a3..378861b9a1fcc 100644 --- a/src/platforms/apple/common/configuration/http-client-errors.mdx +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -4,7 +4,7 @@ sidebar_order: 13 description: "This feature, once enabled, automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry" --- -This feature, once enabled, automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. The error event will contain the `request` and `response` data, such as `url`, `status_code`, and so on. +Once enabled, this feature automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. The error event will contain the `request` and `response` data, such as `url`, `status_code`, and so on. This feature is opt-in and can be enabled by setting the `enableCaptureFailedRequests` option to `true`: From 6216eab0ed65abfd3508543cc890048b0bffdc96 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:45:51 +0100 Subject: [PATCH 04/10] Update src/platforms/apple/common/configuration/http-client-errors.mdx Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/apple/common/configuration/http-client-errors.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx index 378861b9a1fcc..813f57331263b 100644 --- a/src/platforms/apple/common/configuration/http-client-errors.mdx +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -26,7 +26,7 @@ SentrySDK.start { options in }]; ``` -This feature requires the setting `enableSwizzling` to be enabled as well. +To use this feature, you must also enable the `enableSwizzling` setting. By default, only HTTP client errors with a response code between `500` and `599` are captured as error events, but you can change this behavior by setting the `failedRequestStatusCodes` option: From fc094411a84572d13356ff01b043cb4b2e757dd8 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:46:08 +0100 Subject: [PATCH 05/10] Update src/platforms/common/configuration/options.mdx Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/common/configuration/options.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/common/configuration/options.mdx b/src/platforms/common/configuration/options.mdx index ba06c3374bbea..8b65ed144d7cc 100644 --- a/src/platforms/common/configuration/options.mdx +++ b/src/platforms/common/configuration/options.mdx @@ -509,7 +509,7 @@ _(New in version 6.6.0)_ -This feature, once enabled, automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. +Once enabled, this feature automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. From 21727941e535f5eecb535477f2a542ea362a28c9 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:46:31 +0100 Subject: [PATCH 06/10] Update src/platforms/apple/common/configuration/http-client-errors.mdx Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/apple/common/configuration/http-client-errors.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx index 813f57331263b..7793d92297112 100644 --- a/src/platforms/apple/common/configuration/http-client-errors.mdx +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -73,7 +73,7 @@ SentrySDK.start { options in Error events may contain PII data, such as `Headers` and `Cookies`, Sentry already does data scrubbing by default, but you can scrub any data before it is sent, learn more about it in the [Scrubbing Sensitive Data docs](/platforms/apple/guides/ios/data-management/sensitive-data/). -Those events are searchable and you can set alerts on them if you use the `http.url` and `http.status_code` properties. Learn more in our full [Searchable Properties](/product/sentry-basics/search/searchable-properties/) documentation. +These events are searchable and you can set alerts on them if you use the `http.url` and `http.status_code` properties. Learn more in our full [Searchable Properties](/product/sentry-basics/search/searchable-properties/) documentation. ### Customize or Drop the Error Event From 3d0ae3a9f3892f60b7de3aa9bd6e37fb7d7120b7 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:46:46 +0100 Subject: [PATCH 07/10] Update src/platforms/apple/common/configuration/http-client-errors.mdx Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/apple/common/configuration/http-client-errors.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx index 7793d92297112..bd274a433ed60 100644 --- a/src/platforms/apple/common/configuration/http-client-errors.mdx +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -71,7 +71,7 @@ SentrySDK.start { options in }]; ``` -Error events may contain PII data, such as `Headers` and `Cookies`, Sentry already does data scrubbing by default, but you can scrub any data before it is sent, learn more about it in the [Scrubbing Sensitive Data docs](/platforms/apple/guides/ios/data-management/sensitive-data/). +Error events may contain PII data, such as `Headers` and `Cookies`. Sentry already does data scrubbing by default, but you can scrub any data before it is sent. Learn more in [Scrubbing Sensitive Data](/platforms/apple/guides/ios/data-management/sensitive-data/). These events are searchable and you can set alerts on them if you use the `http.url` and `http.status_code` properties. Learn more in our full [Searchable Properties](/product/sentry-basics/search/searchable-properties/) documentation. From 696a93becd35b5530834b1f20069260a24b72369 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:46:55 +0100 Subject: [PATCH 08/10] Update src/platforms/apple/common/configuration/http-client-errors.mdx Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/apple/common/configuration/http-client-errors.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx index bd274a433ed60..bd0a93d59b96d 100644 --- a/src/platforms/apple/common/configuration/http-client-errors.mdx +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -51,7 +51,7 @@ SentrySDK.start { options in }]; ``` -HTTP client errors from every target (`.*` regular expression) are automatically captured, but you can change this behavior by setting the `failedRequestTargets` option with either a regular expression or a plain `String`. A plain string must contain at least one of the items from the list. Plain strings don't have to be full matches, meaning the URL of a request is matched when it contains a string provided through the option. +HTTP client errors from every target (`.*` regular expression) are automatically captured, but you can change this behavior by setting the `failedRequestTargets` option with either a regular expression or a plain `String`. A plain string must contain at least one of the items from the list. Plain strings don't have to be full matches, meaning the URL of a request is matched when it contains a string provided through the option: ```swift {tabTitle:Swift} import Sentry From 2913cf802ccec0f6a875ac3ba40791db8393f919 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:47:07 +0100 Subject: [PATCH 09/10] Update src/platforms/apple/common/configuration/http-client-errors.mdx Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/apple/common/configuration/http-client-errors.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx index bd0a93d59b96d..c913b1a3711f2 100644 --- a/src/platforms/apple/common/configuration/http-client-errors.mdx +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -6,7 +6,7 @@ description: "This feature, once enabled, automatically captures HTTP client err Once enabled, this feature automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. The error event will contain the `request` and `response` data, such as `url`, `status_code`, and so on. -This feature is opt-in and can be enabled by setting the `enableCaptureFailedRequests` option to `true`: +Sending HTTP client errors is an opt-in feature and can be enabled by setting the `enableCaptureFailedRequests` option to `true`: ```swift {tabTitle:Swift} import Sentry From b46d32f309f05870dc6db864c05db2e40b2321a9 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Fri, 4 Nov 2022 07:38:54 +0100 Subject: [PATCH 10/10] review --- src/platform-includes/getting-started-config/apple.mdx | 3 +++ .../apple/common/configuration/http-client-errors.mdx | 2 -- src/wizard/apple/ios.md | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platform-includes/getting-started-config/apple.mdx b/src/platform-includes/getting-started-config/apple.mdx index 901ba963adb40..b82b3a21c3411 100644 --- a/src/platform-includes/getting-started-config/apple.mdx +++ b/src/platform-includes/getting-started-config/apple.mdx @@ -16,6 +16,7 @@ func application(_ application: UIApplication, options.enableAppHangTracking = true options.enableFileIOTracking = true options.enableCoreDataTracking = true + options.enableCaptureFailedRequests = true } return true @@ -35,6 +36,7 @@ func application(_ application: UIApplication, options.enableAppHangTracking = YES; options.enableFileIOTracking = YES; options.enableCoreDataTracking = YES; + options.enableCaptureFailedRequests = YES; }]; return YES; @@ -57,6 +59,7 @@ struct SwiftUIApp: App { options.enableAppHangTracking = true options.enableFileIOTracking = true options.enableCoreDataTracking = true + options.enableCaptureFailedRequests = true } } } diff --git a/src/platforms/apple/common/configuration/http-client-errors.mdx b/src/platforms/apple/common/configuration/http-client-errors.mdx index c913b1a3711f2..880763820d3f0 100644 --- a/src/platforms/apple/common/configuration/http-client-errors.mdx +++ b/src/platforms/apple/common/configuration/http-client-errors.mdx @@ -26,8 +26,6 @@ SentrySDK.start { options in }]; ``` -To use this feature, you must also enable the `enableSwizzling` setting. - By default, only HTTP client errors with a response code between `500` and `599` are captured as error events, but you can change this behavior by setting the `failedRequestStatusCodes` option: ```swift {tabTitle:Swift} diff --git a/src/wizard/apple/ios.md b/src/wizard/apple/ios.md index ef0143fa4fed8..40e1c343c54b5 100644 --- a/src/wizard/apple/ios.md +++ b/src/wizard/apple/ios.md @@ -42,6 +42,7 @@ func application(_ application: UIApplication, options.enableAppHangTracking = true options.enableFileIOTracking = true options.enableCoreDataTracking = true + options.enableCaptureFailedRequests = true } return true @@ -68,6 +69,7 @@ struct SwiftUIApp: App { options.enableAppHangTracking = true options.enableFileIOTracking = true options.enableCoreDataTracking = true + options.enableCaptureFailedRequests = true } } }