fix otel status (#92)

* fix otel status

* bump
pull/92/merge
Conrad Ludgate 2023-05-15 11:45:55 +01:00 committed by GitHub
parent af1080f21c
commit 385314a298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View File

@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.4.3] - 2023-05-15
### Fixed
- Fix span and http status codes
## [0.4.2] - 2023-05-12 ## [0.4.2] - 2023-05-12
### Added ### Added

View File

@ -1,6 +1,6 @@
[package] [package]
name = "reqwest-tracing" name = "reqwest-tracing"
version = "0.4.2" version = "0.4.3"
authors = ["Rodrigo Gryzinski <rodrigo.gryzinski@truelayer.com>"] authors = ["Rodrigo Gryzinski <rodrigo.gryzinski@truelayer.com>"]
edition = "2018" edition = "2018"
description = "Opentracing middleware for reqwest." description = "Opentracing middleware for reqwest."

View File

@ -23,8 +23,8 @@ pub const NET_HOST_PORT: &str = "net.host.port";
pub const OTEL_KIND: &str = "otel.kind"; pub const OTEL_KIND: &str = "otel.kind";
/// The `otel.name` field added to the span by [`reqwest_otel_span`] /// The `otel.name` field added to the span by [`reqwest_otel_span`]
pub const OTEL_NAME: &str = "otel.name"; pub const OTEL_NAME: &str = "otel.name";
/// The `otel.status_code.code` field added to the span by [`reqwest_otel_span`] /// The `otel.status_code` field added to the span by [`reqwest_otel_span`]
pub const OTEL_STATUS_CODE: &str = "http.status_code"; pub const OTEL_STATUS_CODE: &str = "otel.status_code";
/// The `error.message` field added to the span by [`reqwest_otel_span`] /// The `error.message` field added to the span by [`reqwest_otel_span`]
pub const ERROR_MESSAGE: &str = "error.message"; pub const ERROR_MESSAGE: &str = "error.message";
/// The `error.cause_chain` field added to the span by [`reqwest_otel_span`] /// The `error.cause_chain` field added to the span by [`reqwest_otel_span`]
@ -61,12 +61,11 @@ pub fn default_on_request_end(span: &Span, outcome: &Result<Response>) {
#[inline] #[inline]
pub fn default_on_request_success(span: &Span, response: &Response) { pub fn default_on_request_success(span: &Span, response: &Response) {
let span_status = get_span_status(response.status()); let span_status = get_span_status(response.status());
let status_code = response.status().as_u16() as i64;
let user_agent = get_header_value("user_agent", response.headers()); let user_agent = get_header_value("user_agent", response.headers());
if let Some(span_status) = span_status { if let Some(span_status) = span_status {
span.record(OTEL_STATUS_CODE, span_status); span.record(OTEL_STATUS_CODE, span_status);
} }
span.record(HTTP_STATUS_CODE, status_code); span.record(HTTP_STATUS_CODE, response.status().as_u16());
span.record(HTTP_USER_AGENT, user_agent.as_str()); span.record(HTTP_USER_AGENT, user_agent.as_str());
} }
@ -79,13 +78,9 @@ pub fn default_on_request_failure(span: &Span, e: &Error) {
span.record(ERROR_MESSAGE, error_message.as_str()); span.record(ERROR_MESSAGE, error_message.as_str());
span.record(ERROR_CAUSE_CHAIN, error_cause_chain.as_str()); span.record(ERROR_CAUSE_CHAIN, error_cause_chain.as_str());
if let Error::Reqwest(e) = e { if let Error::Reqwest(e) = e {
span.record( if let Some(status) = e.status() {
HTTP_STATUS_CODE, span.record(HTTP_STATUS_CODE, status.as_u16());
e.status() }
.map(|s| s.to_string())
.unwrap_or_else(|| "".to_string())
.as_str(),
);
} }
} }