2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 11:21:24 +00:00

Remove tracing-error workaround

This commit is contained in:
Aode (lion) 2021-09-18 16:34:23 -05:00
parent 5e9d923d03
commit 79a0fa32ee
4 changed files with 12 additions and 62 deletions

20
Cargo.lock generated
View file

@ -387,9 +387,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.7.0"
version = "3.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538"
[[package]]
name = "byteorder"
@ -2026,9 +2026,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
[[package]]
name = "tracing"
version = "0.1.27"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2ba9ab62b7d6497a8638dfda5e5c4fb3b2d5a7fca4118f2b96151c8ef1a437e"
checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8"
dependencies = [
"cfg-if",
"log",
@ -2040,11 +2040,9 @@ dependencies = [
[[package]]
name = "tracing-actix-web"
version = "0.4.0-beta.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aef43d92080b0429626deba48d01dad848ad515777b373d7a18eac3f129be359"
source = "git+https://github.com/asonix/tracing-actix-web?branch=asonix/tracing-error-work-around#51e7911af7d1dd6a9c8265fa19b94224ddff56e2"
dependencies = [
"actix-web",
"futures",
"tracing",
"tracing-futures",
"uuid",
@ -2126,9 +2124,9 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
version = "0.2.22"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62af966210b88ad5776ee3ba12d5f35b8d6a2b2a12168f3080cf02b814d7376b"
checksum = "56c42e73a9d277d4d2b6a88389a137ccf3c58599660b17e8f5fc39305e490669"
dependencies = [
"ansi_term 0.12.1",
"chrono",
@ -2203,9 +2201,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
[[package]]
name = "unicode-width"
version = "0.1.8"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"

View file

@ -35,7 +35,7 @@ time = { version = "0.3.0", features = ["serde"] }
tokio = { version = "1", default-features = false, features = ["fs", "io-util", "process", "sync"] }
tokio-util = { version = "0.6", default-features = false, features = ["codec"] }
tracing = "0.1.15"
tracing-actix-web = { version = "0.4.0-beta.8" }
tracing-actix-web = { version = "0.4.0-beta.8", git = "https://github.com/asonix/tracing-actix-web", branch = "asonix/tracing-error-work-around" }
tracing-error = "0.1.2"
tracing-futures = "0.2.4"
tracing-log = "0.1.2"

View file

@ -45,7 +45,6 @@ mod middleware;
mod migrate;
mod processor;
mod range;
mod root_span_builder;
mod stream;
mod upload_manager;
mod validate;
@ -54,7 +53,6 @@ use self::{
config::{Config, Format},
error::{Error, UploadError},
middleware::{Deadline, Internal},
root_span_builder::RootSpanBuilder,
upload_manager::{Details, UploadManager, UploadManagerSession},
validate::{image_webp, video_mp4},
};
@ -892,11 +890,11 @@ async fn main() -> Result<(), anyhow::Error> {
HttpServer::new(move || {
let client = Client::builder()
.header("User-Agent", "pict-rs v0.1.0-master")
.header("User-Agent", "pict-rs v0.3.0-main")
.finish();
App::new()
.wrap(TracingLogger::<RootSpanBuilder>::new())
.wrap(TracingLogger::default())
.wrap(Deadline)
.app_data(web::Data::new(manager.clone()))
.app_data(web::Data::new(client))

View file

@ -1,46 +0,0 @@
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");
}
}