HTTP Client

Guidelines for HTTP client integrations — breadcrumbs, spans, trace headers, DSN exclusion, and automatic error capture.

Statusstable
Version1.0.0(changelog)

HTTP client integrations instrument outgoing HTTP requests to capture breadcrumbs, create performance spans, and optionally capture HTTP client errors as Sentry events.

Every HTTP client integration MUST exclude HTTP requests that match the configured DSN in the Options to exclude HTTP requests to Sentry.


Stablespecified since 1.0.0

Add a breadcrumb for each outgoing HTTP request after the request finishes:

  • type: http
  • category: http
  • level
    • info - response status code 2XX - 3XX
    • warning - response status code 4XX
    • error - response status code 5XX
  • data (all fields are optional but recommended):
    • url - The URL used in the HTTP request
    • http.request.method - uppercase HTTP method, i.e: GET, HEAD
    • http.response.status_code - Numeric status code such as 200 or 404
    • http.query - The query part of the URL
    • http.fragment - The fragment part of the URI (Browser SDKs only)
    • http.request.body.size Size in bytes
    • http.response.body.size Size in bytes
Stablespecified since 1.0.0

If Performance Monitoring is both supported by the SDK and enabled in the client application when the transaction is active a new Span must be created around the HTTP request:

Stablespecified since 1.0.0

The SDK automatically captures HTTP Client errors and sends them to sentry.io.

The HTTP Client integration should have 3 configuration options:

  • captureFailedRequests defaults to false when introducing this feature due to PII reasons and can be changed to true in a follow up major.
    • The SDK will only capture HTTP Client errors if it is enabled.
  • failedRequestStatusCodes defaults to 500 - 599, this configuration option accepts a List of HttpStatusCodeRange which is a range of HTTP status code -> min to max or a single status_code.
    • The SDK will only capture HTTP Client errors if the HTTP Response status code is within the defined ranges in failedRequestStatusCodes.
    • If the language has a Range type, it should be used instead of HttpStatusCodeRange.
  • failedRequestTargets defaults to (.*), this configuration option accepts a List of String that may be Regular expressions as well, similar to tracePropagationTargets.
    • The SDK will only capture HTTP Client errors if the HTTP Request URL is a match for any of the failedRequestsTargets.
  • While the keys of sensitive HTTP headers (e.g. Authorization and Cookie) are included, their values must be replaced with "[Filtered]" (also see Data Handling: Sensitive Data).

The HTTP Client integration should capture error events with the following properties:

The Request interface, see the Spec for details.

The Response context, see the Spec for details.

Copied
{
  "contexts": {
    "response": {
      "type": "response",
      "cookies": "PHPSESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;",
      "headers": {
        "content-type": "text/html"
        /// ...
      },
      "status_code": 500,
      "body_size": 1000 // in bytes
    }
  }
}

The Exception Interface, see the Errors spec for details.

If the HTTP Client integration does not throw an exception for unsuccessful requests, you can create a synthetic exception following this spec:

When capturing error events, pass the original Request and Response objects from the HTTP Client as hints, so the users may filter out events in beforeSend with the full context.

Automatically captured HTTP Client error events can be searchable and alertable with the http.url and http.status_code properties, learn more about it in the Searchable Properties docs.

As an example, see the OkHTTP Client integration for Android.


VersionDateSummary
1.0.02025-02-24Initial spec, extracted from expected features
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").