1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
}
}