Skip to content

Add docs for JavaScript HttpClient Integration. #6022

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

Merged
merged 3 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/platform-includes/configuration/http-client/javascript.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
```javascript {tabTitle: JavaScript}
import * as Sentry from "@sentry/browser";
import { HttpClient as HttpClientIntegration } from "@sentry/integrations";

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
new HttpClientIntegration({
// This array can contain tuples of `[begin, end]` (both inclusive),
// single status codes, or a combination of both.
// default: [[500, 599]]
failedRequestStatusCodes: [[500, 505], 507],

// This array can contain Regexes, strings, or a combination of both.
// default: [/.*/]
failedRequestTargets: [
"http://example.com/api/test",
/(staging\.)?mypage\.com/,
],
}),
],

// This option is required for capturing headers and cookies.
sendDefaultPii: true,
});
```

```javascript {tabTitle: CDN}
<script
src="https://browser.sentry-cdn.com/{{ packages.version('sentry.javascript.browser') }}/bundle.min.js"
integrity="sha384-{{ packages.checksum('sentry.javascript.browser', 'bundle.min.js', 'sha384-base64') }}"
crossorigin="anonymous"
></script>

<script
src="https://browser.sentry-cdn.com/{{ packages.version('sentry.javascript.browser') }}/httpclient.min.js"
integrity="sha384-{{ packages.checksum('sentry.javascript.browser', 'httpclient.min.js', 'sha384-base64') }}"
crossorigin="anonymous"
></script>

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
new HttpClientIntegration({
// This array can contain tuples of `[begin, end]` (both inclusive),
// single status codes, or a combination of both.
// default: [[500, 599]]
failedRequestStatusCodes: [[500, 505], 507],

// This array can contain Regexes, strings, or a combination of both.
// default: [/.*/]
failedRequestTargets: [
"http://example.com/api/test",
/(staging\.)?mypage\.com/,
],
}),
],

// This option is required for capturing headers and cookies.
sendDefaultPii: true,
});
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Pluggable Integrations
description: "Learn more about pluggable integrations ExtraErrorData, CaptureConsole, Debug, Offline, RewriteFrames, and ReportingObserver, which are snippets of code that augment functionality for specific applications and/or frameworks."
description: "Learn more about pluggable integrations ExtraErrorData, CaptureConsole, Debug, HttpClient, Offline, RewriteFrames, and ReportingObserver, which are snippets of code that augment functionality for specific applications and/or frameworks."
redirect_from:
- /platforms/javascript/integrations/plugin/
- /platforms/javascript/pluggable-integrations/
Expand Down Expand Up @@ -50,6 +50,26 @@ Available options:

<PlatformContent includePath="configuration/debug" />

### HttpClient

_(New in version 7.30.0)_

_Import name: `Sentry.Integrations.HttpClient`_

This integration captures errors on failed requests from Fetch and XHR and attaches request and response information.

By default, error events will not contain header and cookie data. You can change this behavior by setting the `sendDefaultPii` option to `true`.

Available options:

<PlatformContent includePath="configuration/http-client" />

<Alert level="warning" title="Note">

Due to the limitations of both the Fetch and XHR API, the cookie and header collection for both requests and responses is based on best effort. Certain headers may be missing in the event created by the integration.

</Alert>

<PlatformSection notSupported={["javascript.electron"]}>

### Offline
Expand Down