-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP Client errors docs for iOS #5702
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b23313
HTTP Client errors docs for iOS
marandaneto 0749fd1
fix
marandaneto e167cf4
Update src/platforms/apple/common/configuration/http-client-errors.mdx
marandaneto 6216eab
Update src/platforms/apple/common/configuration/http-client-errors.mdx
marandaneto fc09441
Update src/platforms/common/configuration/options.mdx
marandaneto 2172794
Update src/platforms/apple/common/configuration/http-client-errors.mdx
marandaneto 3d0ae3a
Update src/platforms/apple/common/configuration/http-client-errors.mdx
marandaneto 696a93b
Update src/platforms/apple/common/configuration/http-client-errors.mdx
marandaneto 2913cf8
Update src/platforms/apple/common/configuration/http-client-errors.mdx
marandaneto b46d32f
review
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/platforms/apple/common/configuration/http-client-errors.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
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" | ||
--- | ||
|
||
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. | ||
|
||
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 | ||
|
||
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; | ||
}]; | ||
``` | ||
|
||
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 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. | ||
|
||
### 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; | ||
} | ||
}]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 for adding it here.