diff --git a/http-signature-normalization-actix/Cargo.toml b/http-signature-normalization-actix/Cargo.toml index aa2acb4..064dc4b 100644 --- a/http-signature-normalization-actix/Cargo.toml +++ b/http-signature-normalization-actix/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "http-signature-normalization-actix" description = "An HTTP Signatures library that leaves the signing to you" -version = "0.5.0-beta.7" +version = "0.5.0-beta.8" authors = ["asonix "] license-file = "LICENSE" readme = "README.md" @@ -41,5 +41,5 @@ tracing-futures = "0.2" [dev-dependencies] actix-rt = "2.1.0" -tracing-actix-web = { version = "0.4.0-beta.12", git = "https://github.com/asonix/tracing-actix-web", branch = "asonix/root-span-expansion" } +tracing-actix-web = { version = "0.4.0-beta.13" } tracing-subscriber = { version = "0.2", features = ["fmt"] } diff --git a/http-signature-normalization-actix/examples/server.rs b/http-signature-normalization-actix/examples/server.rs index 53e85de..907cc1a 100644 --- a/http-signature-normalization-actix/examples/server.rs +++ b/http-signature-normalization-actix/examples/server.rs @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box> { App::new() .wrap(VerifyDigest::new(Sha256::new()).optional()) .wrap(VerifySignature::new(MyVerify, config.clone()).optional()) - .wrap(TracingLogger::::new()) + .wrap(TracingLogger::default()) .route("/", web::post().to(index)) }) .bind("127.0.0.1:8010")? @@ -102,52 +102,3 @@ impl ResponseError for MyError { HttpResponse::BadRequest().finish() } } - -// tracing-actix-web + tracing-error WORKAROUND - -use actix_web::{ - dev::{ServiceRequest, ServiceResponse}, - Error, -}; -use tracing::Span; -use tracing_actix_web::root_span; - -pub struct RootSpanBuilder; - -impl tracing_actix_web::RootSpanBuilder for RootSpanBuilder { - fn on_request_start(request: &ServiceRequest) -> Span { - root_span!(request) - } - - fn on_request_end(span: Span, outcome: &Result, Error>) { - match &outcome { - Ok(response) => { - if let Some(error) = response.response().error() { - handle_error(span, error) - } else { - span.record("http.status_code", &response.response().status().as_u16()); - span.record("otel.status_code", &"OK"); - } - } - Err(error) => handle_error(span, error), - } - } -} - -fn handle_error(span: Span, error: &Error) { - let response_error = error.as_response_error(); - - let display = format!("{}", response_error); - let debug = format!("{:?}", response_error); - span.record("exception.message", &tracing::field::display(display)); - span.record("exception.details", &tracing::field::display(debug)); - - let status_code = response_error.status_code(); - span.record("http.status_code", &status_code.as_u16()); - - if status_code.is_client_error() { - span.record("otel.status_code", &"OK"); - } else { - span.record("otel.status_code", &"ERROR"); - } -}