tcrm_task/helper/
tracing.rs

1use std::future::Future;
2
3#[cfg(feature = "tracing")]
4use tracing::{Instrument, Level};
5
6pub trait MaybeInstrument: Future + Sized {
7    #[cfg(feature = "tracing")]
8    fn maybe_instrument(self, name: &'static str) -> impl Future<Output = Self::Output> {
9        let span = tracing::span!(Level::DEBUG, "async_op", name = name);
10        self.instrument(span)
11    }
12
13    #[cfg(not(feature = "tracing"))]
14    fn maybe_instrument(self, _name: &'static str) -> Self {
15        self
16    }
17}
18
19impl<F: Future> MaybeInstrument for F {}