mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-27 11:26:31 +00:00
Update otel.status_code
mapping with latest version of spec. (#41)
Co-authored-by: James Hinshelwood <james.hinshelwood@bigpayme.com> Signed-off-by: James Hinshelwood <jameshinshelwood1@gmail.com> Co-authored-by: James Hinshelwood <james.hinshelwood@bigpayme.com>
This commit is contained in:
parent
8f6af94914
commit
762007b524
2 changed files with 14 additions and 18 deletions
|
@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix how we set the OpenTelemetry span status, based on the HTTP response status.
|
||||||
|
|
||||||
# [0.2.2] - 2022-04-21
|
# [0.2.2] - 2022-04-21
|
||||||
### Fixed
|
### Fixed
|
||||||
- Opentelemetry context is now propagated when the request span is disabled.
|
- Opentelemetry context is now propagated when the request span is disabled.
|
||||||
|
|
|
@ -95,28 +95,21 @@ fn get_header_value(key: &str, headers: &HeaderMap) -> String {
|
||||||
format!("{:?}", headers.get(key).unwrap_or(header_default)).replace('"', "")
|
format!("{:?}", headers.get(key).unwrap_or(header_default)).replace('"', "")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HTTP Mapping <https://github.com/open-telemetry/opentelemetry-specification/blob/c4b7f4307de79009c97b3a98563e91fee39b7ba3/work_in_progress/opencensus/HTTP.md#status>
|
/// HTTP Mapping <https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status>
|
||||||
// | HTTP code | Span status code |
|
|
||||||
// |-------------------------|-----------------------|
|
|
||||||
// | 100...299 | `Ok` |
|
|
||||||
// | 3xx redirect codes | `DeadlineExceeded` in case of loop (see above) [1], otherwise `Ok` |
|
|
||||||
// | 401 Unauthorized ⚠ | `Unauthenticated` ⚠ (Unauthorized actually means unauthenticated according to [RFC 7235][rfc-unauthorized]) |
|
|
||||||
// | 403 Forbidden | `PermissionDenied` |
|
|
||||||
// | 404 Not Found | `NotFound` |
|
|
||||||
// | 429 Too Many Requests | `ResourceExhausted` |
|
|
||||||
// | Other 4xx code | `InvalidArgument` [1] |
|
|
||||||
// | 501 Not Implemented | `Unimplemented` |
|
|
||||||
// | 503 Service Unavailable | `Unavailable` |
|
|
||||||
// | 504 Gateway Timeout | `DeadlineExceeded` |
|
|
||||||
// | Other 5xx code | `InternalError` [1] |
|
|
||||||
// | Any status code the client fails to interpret (e.g., 093 or 573) | `UnknownError` |
|
|
||||||
///
|
///
|
||||||
/// Maps the the http status to an Opentelemetry span status following the the specified convention above.
|
/// Maps the the http status to an Opentelemetry span status following the the specified convention above.
|
||||||
fn get_span_status(request_status: RequestStatusCode) -> Option<&'static str> {
|
fn get_span_status(request_status: RequestStatusCode) -> Option<&'static str> {
|
||||||
match request_status.as_u16() {
|
match request_status.as_u16() {
|
||||||
100..=399 => Some("OK"),
|
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges, unless there was
|
||||||
400..=599 => Some("ERROR"),
|
// another error (e.g., network error receiving the response body; or 3xx codes with max redirects exceeded),
|
||||||
_ => None,
|
// in which case status MUST be set to Error.
|
||||||
|
100..=399 => None,
|
||||||
|
// For HTTP status codes in the 4xx range span status MUST be left unset in case of SpanKind.SERVER and MUST be
|
||||||
|
// set to Error in case of SpanKind.CLIENT.
|
||||||
|
400..=499 => Some("ERROR"),
|
||||||
|
// For HTTP status codes in the 5xx range, as well as any other code the client failed to interpret, span
|
||||||
|
// status MUST be set to Error.
|
||||||
|
_ => Some("ERROR"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue