Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
add some methods for getting current span and trace ids
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Aug 6, 2023
1 parent 854bbe4 commit 6fbe7e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 28 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,11 +123,33 @@ pub fn new_span_id() -> Option<SpanId> {
ambient().new_span_id()
}

#[track_caller]
pub fn current_span_id() -> Option<SpanId> {
let mut span_id = None;

ambient().with_current(|ctxt| {
span_id = ctxt.span_id();
});

span_id
}

#[track_caller]
pub fn new_trace_id() -> Option<TraceId> {
ambient().new_trace_id()
}

#[track_caller]
pub fn current_trace_id() -> Option<TraceId> {
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()
Expand Down
2 changes: 1 addition & 1 deletion tests/smoke-test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 6fbe7e1

Please sign in to comment.