Skip to content

HttpClient | Sentry for Next.js

Source URL: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/httpclient

This integration only works inside a browser environment.

Import name: Sentry.httpClientIntegration

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

By default, error events don’t contain header or cookie data. You can change this behavior by setting sendDefaultPii: true in your root Sentry.init({}) config.

import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [Sentry.httpClientIntegration()]
// This option is required for capturing headers and cookies.
sendDefaultPii: true,
});

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

Type: (number|[number, number])[]

This array can contain tuples of [begin, end] (both inclusive), single status codes, or a combination of the two. Default: [[500, 599]]

Type: (string|RegExp)[]

An array of request targets that should be considered, for example ['http://example.com/api/test'] would interpret any request to this URL as a failure. This array can contain Regexes, strings, or a combination of the two. Default: [/.*/]

Type: boolean

This option has to be specified on the root Sentry.init options, not the integration options!

This option is required for capturing headers and cookies.