HTTP Client
Guidelines for HTTP client integrations — breadcrumbs, spans, trace headers, DSN exclusion, and automatic error capture.
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.
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:
- operation:
http.client - description:
$METHOD $url(uppercase HTTP method), e.g.GET https://sentry.io - HTTP requests must be enhanced with a
sentry-traceHTTP header to support distributed tracing - HTTP requests must be enhanced with a
baggageHTTP header to support dynamic sampling - span status must match HTTP response status code (see Span status to HTTP status code mapping)
- when network error occurs, span status must be set to
internal_error - span data must follow the Span Data Conventions
The SDK automatically captures HTTP Client errors and sends them to sentry.io.
The HTTP Client integration should have 3 configuration options:
captureFailedRequestsdefaults tofalsewhen introducing this feature due to PII reasons and can be changed totruein a follow up major.- The SDK will only capture HTTP Client errors if it is enabled.
failedRequestStatusCodesdefaults to500 - 599, this configuration option accepts aListofHttpStatusCodeRangewhich is a range of HTTP status code ->mintomaxor a singlestatus_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
Rangetype, it should be used instead ofHttpStatusCodeRange.
- The SDK will only capture HTTP Client errors if the HTTP Response status code is within the defined ranges in
failedRequestTargetsdefaults to (.*), this configuration option accepts aListofStringthat 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.
- The SDK will only capture HTTP Client errors if the HTTP Request URL is a match for any of the
- While the keys of sensitive HTTP headers (e.g.
AuthorizationandCookie) 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.
{
"contexts": {
"response": {
"type": "response",
"cookies": "PHPSESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;",
"headers": {
"content-type": "text/html"
/// ...
},
"status_code": 500,
"body_size": 1000 // in bytes
}
}
}
{
"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:
- Set the Exception Mechanism with a proper
typesuch asSentryOkHttpInterceptor. - Set the Stack Trace Interface with
snapshot=true.HTTP Client Error with status code: $code.
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.
| Version | Date | Summary |
|---|---|---|
1.0.0 | 2025-02-24 | Initial spec, extracted from expected features |
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").