From 11739cd42c5fcbb2d2aa51e792f6522b24442ae5 Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Mon, 6 Dec 2021 20:35:22 -0600 Subject: [PATCH] Remove fancy span following code --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/id_or_span.rs | 34 ---------------------------------- src/main.rs | 1 - src/process.rs | 33 ++++++++++++++++----------------- 5 files changed, 18 insertions(+), 54 deletions(-) delete mode 100644 src/id_or_span.rs diff --git a/Cargo.lock b/Cargo.lock index 02387a6..13766ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1347,7 +1347,7 @@ dependencies = [ [[package]] name = "pict-rs" -version = "0.3.0-beta.8" +version = "0.3.0-beta.9" dependencies = [ "actix-form-data", "actix-rt", diff --git a/Cargo.toml b/Cargo.toml index a979b61..7b13383 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pict-rs" description = "A simple image hosting service" -version = "0.3.0-beta.8" +version = "0.3.0-beta.9" authors = ["asonix "] license = "AGPL-3.0" readme = "README.md" diff --git a/src/id_or_span.rs b/src/id_or_span.rs deleted file mode 100644 index 8c78887..0000000 --- a/src/id_or_span.rs +++ /dev/null @@ -1,34 +0,0 @@ -use tracing::{Id, Span}; - -pub(crate) enum IdOrSpan { - Id(Option), - Span(Span), -} - -impl IdOrSpan { - pub(crate) fn take(&mut self) -> Self { - std::mem::replace(self, IdOrSpan::Id(None)) - } - - pub(crate) fn from_id(id: Option) -> Self { - IdOrSpan::Id(id) - } - - fn span(&self) -> Option<&Span> { - match self { - IdOrSpan::Span(ref span) => Some(span), - _ => None, - } - } - - pub(crate) fn as_span(&mut self, f: impl Fn(Option) -> Span) -> &Span { - let span = match self.take() { - Self::Id(opt) => f(opt), - Self::Span(span) => span, - }; - - *self = Self::Span(span); - - self.span().expect("Span should always exist") - } -} diff --git a/src/main.rs b/src/main.rs index 1806d30..3c5ccce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,6 @@ mod error; mod exiftool; mod ffmpeg; mod file; -mod id_or_span; mod init_tracing; mod magick; mod map_error; diff --git a/src/process.rs b/src/process.rs index 8e8c428..1363730 100644 --- a/src/process.rs +++ b/src/process.rs @@ -1,4 +1,4 @@ -use crate::{id_or_span::IdOrSpan, store::Store}; +use crate::store::Store; use actix_rt::task::JoinHandle; use actix_web::web::Bytes; use std::{ @@ -13,14 +13,14 @@ use tokio::{ sync::oneshot::{channel, Receiver}, }; use tracing::Instrument; -use tracing::{Id, Span}; +use tracing::Span; #[derive(Debug)] struct StatusError; pub(crate) struct Process { child: Child, - id: Option, + span: Span, } struct DropHandle { @@ -31,7 +31,7 @@ pin_project_lite::pin_project! { struct ProcessRead { #[pin] inner: I, - span: IdOrSpan, + span: Span, err_recv: Receiver, err_closed: bool, handle: DropHandle, @@ -45,9 +45,7 @@ impl Process { fn spawn_span(&self) -> Span { let span = tracing::info_span!(parent: None, "Spawned command writer",); - - span.follows_from(self.id.clone()); - + span.follows_from(self.span.clone()); span } @@ -57,7 +55,7 @@ impl Process { cmd.spawn().map(|child| Process { child, - id: Span::current().id(), + span: Span::current(), }) } @@ -102,7 +100,7 @@ impl Process { Some(ProcessRead { inner: stdout, - span: IdOrSpan::from_id(self.id), + span: body_span(self.span), err_recv: rx, err_closed: false, handle: DropHandle { inner: handle }, @@ -135,7 +133,7 @@ impl Process { Some(ProcessRead { inner: stdout, - span: IdOrSpan::from_id(self.id), + span: body_span(self.span), err_recv: rx, err_closed: false, handle: DropHandle { inner: handle }, @@ -179,7 +177,7 @@ impl Process { Some(ProcessRead { inner: stdout, - span: IdOrSpan::from_id(self.id), + span: body_span(self.span), err_recv: rx, err_closed: false, handle: DropHandle { inner: handle }, @@ -187,6 +185,12 @@ impl Process { } } +fn body_span(following: Span) -> Span { + let span = tracing::info_span!(parent: None, "Processing Command"); + span.follows_from(following); + span +} + impl AsyncRead for ProcessRead where I: AsyncRead, @@ -201,12 +205,7 @@ where let err_recv = this.err_recv; let err_closed = this.err_closed; let inner = this.inner; - - let span = this.span.as_span(|id| { - let span = tracing::info_span!("Processing Command"); - span.follows_from(id); - span - }); + let span = this.span; span.in_scope(|| { if !*err_closed {