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: 'none' | 'small' | 'medium' | 'always' (Defaults to 'medium')

Controls the maximum size of incoming HTTP request bodies attached to events.

Available options:

  • 'none': No request bodies will be attached
  • 'small': Request bodies up to 1,000 bytes will be attached
  • 'medium': Request bodies up to 10,000 bytes will be attached (default)
  • 'always': Request bodies will always be attached

Note that even with the 'always' setting, bodies exceeding 1 MB will never be attached for performance and security reasons.

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

Allows you to ignore the request body for incoming HTTP requests to URLs where the given callback returns true. This can be useful for long running requests where the body is not needed and we want to avoid capturing it.

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: (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;
});
Was this helpful?
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").