Pluggable integrations that enhance Sentry JavaScript SDKs with additional error tracking, monitoring, and debugging capabilities.
—
Monitors HTTP requests made via fetch API and XMLHttpRequest, creating Sentry events for failed requests based on configurable status codes and URL patterns. Useful for tracking API failures and network issues.
/**
* Creates events for failed client-side HTTP requests
* @param options - Configuration for HTTP monitoring
* @returns Integration instance that monitors HTTP requests
*/
function httpClientIntegration(options?: Partial<HttpClientOptions>): Integration;
interface HttpClientOptions {
/** HTTP status codes that should be considered failed */
failedRequestStatusCodes: HttpStatusCodeRange[];
/** Targets to track for failed requests */
failedRequestTargets: HttpRequestTarget[];
}
type HttpStatusCodeRange = [number, number] | number;
type HttpRequestTarget = string | RegExp;/**
* Legacy class-based HTTP client integration
* @deprecated Use httpClientIntegration() instead
*/
class HttpClient implements Integration {
constructor(options?: {
failedRequestStatusCodes: HttpStatusCodeRange[];
failedRequestTargets: HttpRequestTarget[];
});
name: string;
setup(client: Client): void;
}Defines which HTTP status codes should trigger events:
[[500, 599]] (server errors only)[404, 500][[400, 499], [500, 599]] (client and server errors)[[500, 505], 507, 510]Defines which URLs to monitor:
[/.*/] (all URLs)['http://api.example.com', '/api/'][/\/api\/.*/, /admin/]['localhost', /\/api\/v[12]\//]The integration instruments both fetch API and XMLHttpRequest:
addFetchInstrumentationHandler()addXhrInstrumentationHandler()Failed requests generate synthetic error events containing:
Request Information:
sendDefaultPii enabled)sendDefaultPii enabled)Response Information:
{ type: 'http.client', handled: false }Personal data inclusion is controlled by Sentry client's sendDefaultPii option:
import { httpClientIntegration } from '@sentry/integrations';
import * as Sentry from '@sentry/browser';
// Monitor server errors only (default)
Sentry.init({
dsn: 'YOUR_DSN',
integrations: [
httpClientIntegration()
]
});
// Monitor both client and server errors
Sentry.init({
dsn: 'YOUR_DSN',
integrations: [
httpClientIntegration({
failedRequestStatusCodes: [[400, 599]]
})
]
});
// Monitor specific APIs and error codes
Sentry.init({
dsn: 'YOUR_DSN',
integrations: [
httpClientIntegration({
failedRequestStatusCodes: [404, [500, 599]],
failedRequestTargets: [
'https://api.example.com',
/\/api\/v[12]\//,
'localhost:3000'
]
})
]
});
// Include headers and cookies in events
Sentry.init({
dsn: 'YOUR_DSN',
sendDefaultPii: true, // Enables header/cookie capture
integrations: [
httpClientIntegration({
failedRequestStatusCodes: [[400, 499], [500, 599]]
})
]
});Generated events have the following structure:
{
message: "HTTP Client Error with status code: 404",
exception: {
values: [{
type: "Error",
value: "HTTP Client Error with status code: 404"
}]
},
request: {
url: "https://api.example.com/users/123",
method: "GET",
headers: { /* if sendDefaultPii enabled */ },
cookies: { /* if sendDefaultPii enabled */ }
},
contexts: {
response: {
status_code: 404,
headers: { /* if sendDefaultPii enabled */ },
cookies: { /* if sendDefaultPii enabled */ },
body_size: 1234 // from Content-Length header
}
}
}The integration automatically filters out:
This integration is particularly useful for SPAs and applications that make many API calls, providing visibility into client-side network failures.
Install with Tessl CLI
npx tessl i tessl/npm-sentry--integrations