pub trait TracingRuntimeExt {
// Required methods
fn with_tracing_callbacks(&mut self) -> &mut Self;
fn with_tracing_callbacks_and_custom_start<F>(
&mut self,
on_start: F,
) -> &mut Self
where F: Fn() + Send + Sync + 'static;
}Expand description
Extension trait for tokio::runtime::Builder that adds tracing lifecycle callbacks.
This trait provides a convenient way to configure tokio runtimes with the proper thread lifecycle callbacks for micromegas tracing, ensuring that:
- Thread streams are initialized when worker threads start
- Event buffers are flushed when threads park (become idle)
- Thread streams are properly unregistered when threads stop
This is useful in both production applications (like ingestion servers) and tests where you need proper tracing integration with tokio’s thread pool.
§Examples
use micromegas_tracing::runtime::TracingRuntimeExt;
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("my-service")
.with_tracing_callbacks()
.build()
.expect("Failed to build runtime");Required Methods§
Sourcefn with_tracing_callbacks(&mut self) -> &mut Self
fn with_tracing_callbacks(&mut self) -> &mut Self
Configures the runtime builder with standard tracing lifecycle callbacks.
This method adds the following callbacks:
on_thread_start: Initializes thread-local tracing streamon_thread_park: Flushes event buffer when thread becomes idleon_thread_stop: Unregisters thread stream to prevent dangling pointers
Sourcefn with_tracing_callbacks_and_custom_start<F>(
&mut self,
on_start: F,
) -> &mut Self
fn with_tracing_callbacks_and_custom_start<F>( &mut self, on_start: F, ) -> &mut Self
Configures the runtime builder with tracing callbacks and custom thread start logic.
This is useful when you need to perform additional setup during thread start while still maintaining the standard tracing lifecycle.
§Arguments
on_start- Custom function to call in addition toinit_thread_stream()
§Examples
use micromegas_tracing::runtime::TracingRuntimeExt;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
let counter = Arc::new(AtomicUsize::new(0));
let counter_clone = counter.clone();
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.with_tracing_callbacks_and_custom_start(move || {
let id = counter_clone.fetch_add(1, Ordering::Relaxed);
eprintln!("Worker thread {} starting", id);
})
.build()
.expect("Failed to build runtime");Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl TracingRuntimeExt for Builder
Available on crate feature tokio only.
impl TracingRuntimeExt for Builder
tokio only.