Skip to content

Commit

Permalink
examples: return current span in SloggishCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaschoenburg committed Feb 27, 2021
1 parent f94e8be commit 654b790
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions examples/examples/sloggish/sloggish_collector.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ansi_term::{Color, Style};
use tracing::{
field::{Field, Visit},
Collect, Id, Level,
Collect, Id, Level, Metadata,
};
use tracing_core::span::Current;

Expand Down Expand Up @@ -66,6 +66,7 @@ pub struct SloggishCollector {
struct Span {
parent: Option<Id>,
kvs: Vec<(&'static str, String)>,
metadata: &'static Metadata<'static>,
}

struct Event<'a> {
Expand Down Expand Up @@ -93,6 +94,7 @@ impl Span {
let mut span = Self {
parent,
kvs: Vec::new(),
metadata: attrs.metadata(),
};
attrs.record(&mut span);
span
Expand Down Expand Up @@ -268,6 +270,16 @@ impl Collect for SloggishCollector {
}

fn current_span(&self) -> Current {
Current::unknown()
if let Some(id) = self.current.id() {
let metadata = self
.spans
.lock()
.unwrap()
.get(&id)
.unwrap_or_else(|| panic!("no metadata stored for span with ID {:?}", id))
.metadata;
return Current::new(id, metadata);
}
return Current::none();
}
}

0 comments on commit 654b790

Please sign in to comment.