[−][src]Function opentelemetry::trace::get_active_span
pub fn get_active_span<F, T>(f: F) -> T where
F: FnOnce(&dyn Span) -> T,
Executes a closure with a reference to this thread's current span.
Examples
use opentelemetry::{global, trace::{Span, Tracer}, KeyValue}; use opentelemetry::trace::get_active_span; fn my_function() { // start an active span in one function global::tracer("my-component").in_span("span-name", |_cx| { // anything happening in functions we call can still access the active span... my_other_function(); }) } fn my_other_function() { // call methods on the current span from get_active_span(|span| { span.add_event("An event!".to_string(), vec![KeyValue::new("happened", true)]); }) }