Http

Capture spans & breadcrumbs for http requests. (default)

Import name: Sentry.httpIntegration

This integration is enabled by default. If you'd like to modify your default integrations, read this.

The httpIntegration does two things:

  1. It captures breadcrumbs for HTTP requests.
  2. It captures spans for outgoing HTTP requests.
Copied
Sentry.init({
  integrations: [Sentry.httpIntegration()],
});

Type: boolean

If set to false, no breadcrumbs will be captured.

Type: (url: string, request: RequestOptions) => boolean

Allows you to define a method to filter out outgoing requests based on the URL. If the method returns true, no spans or breadcrumbs will be captured for the outgoing request.

The callback function receives two arguments:

  • url: The full URL of the outgoing request, including the protocol, host, port, path and query string. For example: https://example.com/users?name=John.
  • request: An object of type RequestOptions containing the outgoing request's options. You can use this to filter on properties like the request method or headers.

Type: (urlPath: string, request: IncomingMessage) => boolean

Allows you to define a method to filter out incoming requests based on the URL. If the method returns true, no span or transaction will be captured for the incoming request.

The callback function receives two arguments:

  • urlPath: The URL path of the incoming request, including the query string if available. For example: /users?name=John.
  • request: An object of type IncomingMessage containing the incoming request. You can use this to filter on properties like the request method or headers.

Type: boolean (Defaults to true)

Determines whether the integration should create Sessions for incoming requests to track the health and crash-free rate of your releases in Sentry. Read more about Release Health.

You can also pass some hooks through to the underlying OpenTelemetry Instrumentation:

Copied
httpIntegration({
  instrumentation?: {
    requestHook?: (span: Span, req: ClientRequest | HTTPModuleRequestIncomingMessage) => void;
    responseHook?: (span: Span, response: HTTPModuleRequestIncomingMessage | ServerResponse) => void;
    applyCustomAttributesOnSpan?: (
      span: Span,
      request: ClientRequest | HTTPModuleRequestIncomingMessage,
      response: HTTPModuleRequestIncomingMessage | ServerResponse,
    ) => void;
});
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").