Description
Package + Version
-
@sentry/javascript
Version:
6.13.3 (master)
Description
Sentry deciphers all HTTP status codes < 400 as "Ok":
https://github.com/getsentry/sentry-javascript/blob/master/packages/tracing/src/spanstatus.ts#L48-L86
This is problematic because at least XHR leaves the status code at 0 in case of XMLHttpRequest
errors (network failure etc.):
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status
Before the request completes, the value of status is 0. Browsers also report a status of 0 in case of XMLHttpRequest errors.
We had a situation where we were doing custom instrumentation when using RxJS Ajax and setting the status code in Sentry like this:
catchError((error: AjaxError) => {
transaction.setHttpStatus(error.status);
// ...
}),
tap(response => {
transaction.setHttpStatus(response.status);
// ...
}),
and we were wondering why transactions with connection errors ended up showing in Sentry as "Ok" (not counting towards failure rate etc.). This was the reason.
For now we are doing this to skip the problem:
catchError((error: AjaxError) => {
if (error.status === 0) {
transaction.setHttpStatus(599);
} else {
transaction.setHttpStatus(error.status);
}
// ...
}),
tap(response => {
transaction.setHttpStatus(response.status);
// ...
}),
Btw. worth mentioning is that we tried to set the HTTP status code and actual status separately (as Sentry seems to set the http.status
tag on setHttpStatus
) like this:
transaction.setHttpStatus(error.status);
if (error.status === 0) {
transaction.setStatus(SentryTracing.SpanStatus.UnknownError);
}
but this did not seem to have a real influence as it seems like the Sentry backend/UI deciphers failure rate etc. based on the HTTP status code (these did not count towards the failure rate).