mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-10 06:25:00 +00:00
Improve follows-from and parent span relationships
This commit is contained in:
parent
4eec906c5d
commit
920f1f154c
4 changed files with 77 additions and 26 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -127,9 +127,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-server"
|
name = "actix-server"
|
||||||
version = "2.0.0-beta.9"
|
version = "2.0.0-rc.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "411dd3296dd317ff5eff50baa13f31923ea40ec855dd7f2d3ed8639948f0195f"
|
checksum = "78c9b22794b8af1c2e02434873ef858f2a7db40dbbf861ce77a04cd81ac6b767"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
|
@ -137,7 +137,7 @@ dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"mio",
|
"mio 0.8.0",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -1042,9 +1042,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.108"
|
version = "0.2.109"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
|
@ -1154,6 +1154,19 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mio"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"miow",
|
||||||
|
"ntapi",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miow"
|
name = "miow"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
|
@ -1442,9 +1455,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.32"
|
version = "1.0.33"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
|
checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
@ -2096,7 +2109,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"memchr",
|
"memchr",
|
||||||
"mio",
|
"mio 0.7.14",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
@ -2302,9 +2315,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-awc"
|
name = "tracing-awc"
|
||||||
version = "0.1.0-beta.11"
|
version = "0.1.0-beta.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7b79f7237bb46dbb931e2daafc1b89371dcf0759054ec9a2b1df40096a937a8f"
|
checksum = "8093ad66e1a7a3832eb450180abaf1e5f62ace52ff547b46a0b3fddfda8abf78"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-http",
|
"actix-http",
|
||||||
"actix-service",
|
"actix-service",
|
||||||
|
|
34
src/id_or_span.rs
Normal file
34
src/id_or_span.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use tracing::{Id, Span};
|
||||||
|
|
||||||
|
pub(crate) enum IdOrSpan {
|
||||||
|
Id(Option<Id>),
|
||||||
|
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<Id>) -> 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<Id>) -> 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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ mod error;
|
||||||
mod exiftool;
|
mod exiftool;
|
||||||
mod ffmpeg;
|
mod ffmpeg;
|
||||||
mod file;
|
mod file;
|
||||||
|
mod id_or_span;
|
||||||
mod init_tracing;
|
mod init_tracing;
|
||||||
mod magick;
|
mod magick;
|
||||||
mod map_error;
|
mod map_error;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::store::Store;
|
use crate::{id_or_span::IdOrSpan, store::Store};
|
||||||
use actix_rt::task::JoinHandle;
|
use actix_rt::task::JoinHandle;
|
||||||
use actix_web::web::Bytes;
|
use actix_web::web::Bytes;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -13,14 +13,14 @@ use tokio::{
|
||||||
sync::oneshot::{channel, Receiver},
|
sync::oneshot::{channel, Receiver},
|
||||||
};
|
};
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
use tracing::Span;
|
use tracing::{Id, Span};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct StatusError;
|
struct StatusError;
|
||||||
|
|
||||||
pub(crate) struct Process {
|
pub(crate) struct Process {
|
||||||
child: Child,
|
child: Child,
|
||||||
span: Span,
|
id: Option<Id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DropHandle {
|
struct DropHandle {
|
||||||
|
@ -31,7 +31,7 @@ pin_project_lite::pin_project! {
|
||||||
struct ProcessRead<I> {
|
struct ProcessRead<I> {
|
||||||
#[pin]
|
#[pin]
|
||||||
inner: I,
|
inner: I,
|
||||||
span: Span,
|
span: IdOrSpan,
|
||||||
err_recv: Receiver<std::io::Error>,
|
err_recv: Receiver<std::io::Error>,
|
||||||
err_closed: bool,
|
err_closed: bool,
|
||||||
handle: DropHandle,
|
handle: DropHandle,
|
||||||
|
@ -46,21 +46,19 @@ impl Process {
|
||||||
fn spawn_span(&self) -> Span {
|
fn spawn_span(&self) -> Span {
|
||||||
let span = tracing::info_span!(parent: None, "Spawned command writer",);
|
let span = tracing::info_span!(parent: None, "Spawned command writer",);
|
||||||
|
|
||||||
span.follows_from(self.span.clone());
|
span.follows_from(self.id.clone());
|
||||||
|
|
||||||
span
|
span
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(name = "Spawning Command")]
|
||||||
pub(crate) fn spawn(cmd: &mut Command) -> std::io::Result<Self> {
|
pub(crate) fn spawn(cmd: &mut Command) -> std::io::Result<Self> {
|
||||||
let cmd = cmd.stdin(Stdio::piped()).stdout(Stdio::piped());
|
let cmd = cmd.stdin(Stdio::piped()).stdout(Stdio::piped());
|
||||||
|
|
||||||
let span = tracing::info_span!(
|
cmd.spawn().map(|child| Process {
|
||||||
"Spawning Command",
|
child,
|
||||||
command = &tracing::field::debug(&cmd),
|
id: Span::current().id(),
|
||||||
exception.message = &tracing::field::Empty,
|
})
|
||||||
exception.details = &tracing::field::Empty,
|
|
||||||
);
|
|
||||||
cmd.spawn().map(|child| Process { child, span })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn wait(mut self) -> std::io::Result<()> {
|
pub(crate) async fn wait(mut self) -> std::io::Result<()> {
|
||||||
|
@ -104,7 +102,7 @@ impl Process {
|
||||||
|
|
||||||
Some(ProcessRead {
|
Some(ProcessRead {
|
||||||
inner: stdout,
|
inner: stdout,
|
||||||
span: self.span,
|
span: IdOrSpan::from_id(self.id),
|
||||||
err_recv: rx,
|
err_recv: rx,
|
||||||
err_closed: false,
|
err_closed: false,
|
||||||
handle: DropHandle { inner: handle },
|
handle: DropHandle { inner: handle },
|
||||||
|
@ -137,7 +135,7 @@ impl Process {
|
||||||
|
|
||||||
Some(ProcessRead {
|
Some(ProcessRead {
|
||||||
inner: stdout,
|
inner: stdout,
|
||||||
span: self.span,
|
span: IdOrSpan::from_id(self.id),
|
||||||
err_recv: rx,
|
err_recv: rx,
|
||||||
err_closed: false,
|
err_closed: false,
|
||||||
handle: DropHandle { inner: handle },
|
handle: DropHandle { inner: handle },
|
||||||
|
@ -181,7 +179,7 @@ impl Process {
|
||||||
|
|
||||||
Some(ProcessRead {
|
Some(ProcessRead {
|
||||||
inner: stdout,
|
inner: stdout,
|
||||||
span: self.span,
|
span: IdOrSpan::from_id(self.id),
|
||||||
err_recv: rx,
|
err_recv: rx,
|
||||||
err_closed: false,
|
err_closed: false,
|
||||||
handle: DropHandle { inner: handle },
|
handle: DropHandle { inner: handle },
|
||||||
|
@ -200,11 +198,16 @@ where
|
||||||
) -> Poll<std::io::Result<()>> {
|
) -> Poll<std::io::Result<()>> {
|
||||||
let this = self.as_mut().project();
|
let this = self.as_mut().project();
|
||||||
|
|
||||||
let span = this.span;
|
|
||||||
let err_recv = this.err_recv;
|
let err_recv = this.err_recv;
|
||||||
let err_closed = this.err_closed;
|
let err_closed = this.err_closed;
|
||||||
let inner = this.inner;
|
let inner = this.inner;
|
||||||
|
|
||||||
|
let span = this.span.as_span(|id| {
|
||||||
|
let span = tracing::info_span!("Processing Command");
|
||||||
|
span.follows_from(id);
|
||||||
|
span
|
||||||
|
});
|
||||||
|
|
||||||
span.in_scope(|| {
|
span.in_scope(|| {
|
||||||
if !*err_closed {
|
if !*err_closed {
|
||||||
if let Poll::Ready(res) = Pin::new(err_recv).poll(cx) {
|
if let Poll::Ready(res) = Pin::new(err_recv).poll(cx) {
|
||||||
|
|
Loading…
Reference in a new issue