pub struct TraceContext {
pub trace_id: String,
pub span_id: String,
pub parent_span_id: Option<String>,
pub sampled: bool,
}Expand description
Simplified trace context for internal use
Fields§
§trace_id: String§span_id: String§parent_span_id: Option<String>§sampled: boolImplementations§
Source§impl TraceContext
impl TraceContext
Sourcepub fn new_root() -> Self
pub fn new_root() -> Self
Create a new root trace context
Examples found in repository?
examples/integrated_context_demo.rs (line 17)
11fn main() {
12 println!("🔌 observability_core context demo");
13 println!("==================================\n");
14
15 println!("Before: {:?}", get_current_context());
16
17 let root = TraceContext::new_root();
18 let trace_id = root.trace_id.clone();
19
20 let out = with_context(root, || {
21 println!("Inside: {:?}", get_current_context());
22 "ok"
23 });
24
25 println!("After: {:?}", get_current_context());
26 println!("Result: {out} (trace_id={trace_id})");
27}More examples
examples/raii_scoped_context_demo.rs (line 15)
9fn main() {
10 println!("🔒 Scoped trace context demo");
11 println!("============================\n");
12
13 println!("Before: {:?}", get_current_context());
14
15 let ctx = TraceContext::new_root();
16 let tid = ctx.trace_id.clone();
17
18 let out = with_context(ctx, || {
19 log::info!("Processing request");
20 get_current_context().unwrap().trace_id
21 });
22
23 println!("Inside returned trace_id={out}");
24 println!("Expected trace_id={tid}");
25 println!("After: {:?}", get_current_context());
26}Sourcepub fn to_w3c(&self) -> W3CTraceContext
pub fn to_w3c(&self) -> W3CTraceContext
Convert to W3C trace context
Sourcepub fn from_w3c(w3c: &W3CTraceContext) -> Self
pub fn from_w3c(w3c: &W3CTraceContext) -> Self
Create from W3C trace context
Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§fn clone(&self) -> TraceContext
fn clone(&self) -> TraceContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TraceContext
impl RefUnwindSafe for TraceContext
impl Send for TraceContext
impl Sync for TraceContext
impl Unpin for TraceContext
impl UnsafeUnpin for TraceContext
impl UnwindSafe for TraceContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more