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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use once_cell::sync::Lazy;
use prelude::*;
use std::sync::{Arc, Mutex};
use tracing_subscriber::util::TryInitError;
type LazyMutex<T> = Lazy<Arc<Mutex<T>>>;
mod attribute;
mod layer;
mod log;
mod record;
mod report;
static INIT: Lazy<Result<(), TryInitError>> =
Lazy::new(|| tracing_subscriber::registry().with(Layer {}).try_init());
pub fn init() {
Lazy::force(&INIT).as_ref().expect("couldn't set span-test subscriber as a default, maybe tracing has already been initialized somewhere else ?");
}
pub fn get_all_logs(level: &Level) -> Records {
let logs = layer::ALL_LOGS.lock().unwrap().clone();
Records::new(logs.all_records_for_level(level))
}
pub fn get_telemetry_for_root(
root_id: &crate::reexports::tracing::Id,
level: &Level,
) -> (Span, Records) {
let report = Report::from_root(root_id.into_u64());
(report.spans(level), report.logs(level))
}
pub fn get_spans_for_root(root_id: &crate::reexports::tracing::Id, level: &Level) -> Span {
Report::from_root(root_id.into_u64()).spans(level)
}
pub fn get_logs_for_root(root_id: &crate::reexports::tracing::Id, level: &Level) -> Records {
Report::from_root(root_id.into_u64()).logs(level)
}
pub mod prelude {
pub(crate) use crate::layer::Layer;
pub use crate::record::RecordValue;
pub use crate::reexports::tracing::{Instrument, Level};
pub use crate::reexports::tracing_futures::WithSubscriber;
pub use crate::reexports::tracing_subscriber::prelude::*;
pub use crate::report::{Records, Report, Span};
pub use crate::{get_all_logs, get_logs_for_root, get_spans_for_root, get_telemetry_for_root};
pub use test_span_macro::test_span;
}
pub mod reexports {
pub use daggy;
pub use serde;
pub use tracing;
pub use tracing_futures;
pub use tracing_subscriber;
}