#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! trace_span {
($name:expr) => {
tracing::span!(tracing::Level::DEBUG, $name)
};
($name:expr, $($field:tt)*) => {
tracing::span!(tracing::Level::DEBUG, $name, $($field)*)
};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! trace_span {
($name:expr) => {
()
};
($name:expr, $($field:tt)*) => {
()
};
}
#[cfg(not(feature = "tracing"))]
pub struct NoopSpanGuard;
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! trace_enter {
($name:expr) => {
tracing::span!(tracing::Level::DEBUG, $name).entered()
};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! trace_enter {
($name:expr) => {
$crate::trace::NoopSpanGuard
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! trace_event {
($($arg:tt)*) => {
tracing::debug!($($arg)*)
};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! trace_event {
($($arg:tt)*) => {};
}
pub use trace_enter;
pub use trace_event;
pub use trace_span;
#[cfg(test)]
mod tests {
#[test]
fn test_trace_macros_compile() {
let _span = trace_span!("test_span");
let _guard = trace_enter!("test_enter");
trace_event!("test event");
}
}