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
use crate::{span_map::*, Tracer};
pub use rustracing::sampler::AllSampler;
use std::collections::HashMap;
pub fn new_tracer_with_console_reporter() -> (Tracer, ConsoleReporter) {
let (span_tx, span_rx) = crossbeam_channel::bounded(1000);
let tracer = Tracer::with_sender(AllSampler, span_tx);
(tracer, ConsoleReporter::new(span_rx))
}
#[derive(Debug)]
pub struct ConsoleReporter {
span_rx: crossbeam_channel::Receiver<FinishedSpan>,
span_map: SpanMap,
}
impl ConsoleReporter {
pub fn new(span_rx: crossbeam_channel::Receiver<FinishedSpan>) -> Self {
ConsoleReporter {
span_rx,
span_map: HashMap::new(),
}
}
pub fn clear(&mut self) {
let _ = self.drain();
self.span_map.clear();
}
pub fn drain(&mut self) -> u32 {
let mut count = 0;
while let Ok(span) = self.span_rx.try_recv() {
count += 1;
self.span_map.insert(span.context().state().span_id(), span);
}
count
}
pub fn print(&self, only_events: bool) {
print_span_map(&self.span_map, only_events);
}
}