diff --git a/src/lib.rs b/src/lib.rs index 3d9111f..3acc377 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,21 +18,18 @@ pub use emit_core::{ pub mod local_frame; pub use self::{ - ctxt::Ctxt, + ctxt::{Ctxt, ErasedCtxt}, event::Event, - filter::Filter, - id::{IdGen, SpanId, TraceId}, + filter::{ErasedFilter, Filter}, + id::{ErasedIdGen, IdGen, SpanId, TraceId}, key::Key, level::Level, props::Props, - target::Target, + target::{ErasedTarget, Target}, template::Template, - time::{Clock, Timer, Timestamp}, + time::{Clock, ErasedClock, Timer, Timestamp}, value::Value, -}; -use self::{ - ctxt::ErasedCtxt, filter::ErasedFilter, id::ErasedIdGen, target::ErasedTarget, - time::ErasedClock, + well_known::WellKnown, }; mod macro_hooks; @@ -126,11 +123,33 @@ pub fn new_span_id() -> Option { ambient().new_span_id() } +#[track_caller] +pub fn current_span_id() -> Option { + let mut span_id = None; + + ambient().with_current(|ctxt| { + span_id = ctxt.span_id(); + }); + + span_id +} + #[track_caller] pub fn new_trace_id() -> Option { ambient().new_trace_id() } +#[track_caller] +pub fn current_trace_id() -> Option { + let mut trace_id = None; + + ambient().with_current(|ctxt| { + trace_id = ctxt.trace_id(); + }); + + trace_id +} + #[cfg(feature = "std")] pub fn setup() -> setup::Setup { setup::Setup::default() diff --git a/tests/smoke-test/main.rs b/tests/smoke-test/main.rs index af75719..0010634 100644 --- a/tests/smoke-test/main.rs +++ b/tests/smoke-test/main.rs @@ -31,7 +31,7 @@ async fn main() { emitter.blocking_flush(Duration::from_secs(5)); } -#[emit::with(span_id: emit::new_span_id(), a)] +#[emit::with(span_id: emit::new_span_id(), span_parent: emit::current_span_id(), a)] async fn in_ctxt(a: i32) -> Result<(), io::Error> { let extent = emit::start_timer();