use tracing::trace_span;
use tracing_futures::{Instrument, Instrumented};
pub(crate) const FILE_FIELD_NAME: &str = "loc.file";
pub(crate) const LINE_FIELD_NAME: &str = "loc.line";
pub const SPAN_TARGET: &str = "trace_tools::observe";
pub const SPAN_NAME: &str = "observed";
pub trait Observe: Sized {
#[track_caller]
fn observe(self, name: &str) -> Instrumented<Self>;
}
impl<T: Instrument> Observe for T {
#[track_caller]
fn observe(self, name: &str) -> Instrumented<Self> {
let location = std::panic::Location::caller();
let span = trace_span!(
target: SPAN_TARGET,
SPAN_NAME,
observed.name = name,
loc.file = location.file(),
loc.line = location.line(),
loc.col = location.column(),
);
self.instrument(span)
}
}