Bump tracing-actix-web, remove workaround, bump version

This commit is contained in:
Aode (Lion) 2021-09-21 10:43:06 -05:00
parent 11be605f5b
commit be57fcf7dd
2 changed files with 3 additions and 52 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "http-signature-normalization-actix" name = "http-signature-normalization-actix"
description = "An HTTP Signatures library that leaves the signing to you" 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 <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
license-file = "LICENSE" license-file = "LICENSE"
readme = "README.md" readme = "README.md"
@ -41,5 +41,5 @@ tracing-futures = "0.2"
[dev-dependencies] [dev-dependencies]
actix-rt = "2.1.0" 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"] } tracing-subscriber = { version = "0.2", features = ["fmt"] }

View file

@ -68,7 +68,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
App::new() App::new()
.wrap(VerifyDigest::new(Sha256::new()).optional()) .wrap(VerifyDigest::new(Sha256::new()).optional())
.wrap(VerifySignature::new(MyVerify, config.clone()).optional()) .wrap(VerifySignature::new(MyVerify, config.clone()).optional())
.wrap(TracingLogger::<RootSpanBuilder>::new()) .wrap(TracingLogger::default())
.route("/", web::post().to(index)) .route("/", web::post().to(index))
}) })
.bind("127.0.0.1:8010")? .bind("127.0.0.1:8010")?
@ -102,52 +102,3 @@ impl ResponseError for MyError {
HttpResponse::BadRequest().finish() 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<B>(span: Span, outcome: &Result<ServiceResponse<B>, 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");
}
}