#[macro_export]
macro_rules! trace_request {
($protocol:expr, $operation:expr) => {
tracing::info_span!(
"request",
protocol = $protocol,
operation = $operation,
request_id = %uuid::Uuid::new_v4(),
)
};
($protocol:expr, $operation:expr, $($field:tt)*) => {
tracing::info_span!(
"request",
protocol = $protocol,
operation = $operation,
request_id = %uuid::Uuid::new_v4(),
$($field)*
)
};
}
#[macro_export]
macro_rules! trace_device {
($device_id:expr, $operation:expr) => {
tracing::debug_span!(
"device",
device_id = $device_id,
operation = $operation,
)
};
($device_id:expr, $operation:expr, $($field:tt)*) => {
tracing::debug_span!(
"device",
device_id = $device_id,
operation = $operation,
$($field)*
)
};
}
#[macro_export]
macro_rules! trace_success {
($operation:expr, $start:expr) => {
tracing::info!(
operation = $operation,
duration_us = $start.elapsed().as_micros() as u64,
"Operation completed"
);
};
($operation:expr, $start:expr, $($field:tt)*) => {
tracing::info!(
operation = $operation,
duration_us = $start.elapsed().as_micros() as u64,
$($field)*,
"Operation completed"
);
};
}
#[macro_export]
macro_rules! trace_error {
($operation:expr, $error:expr) => {
tracing::error!(
operation = $operation,
error = %$error,
"Operation failed"
);
};
($operation:expr, $error:expr, $($field:tt)*) => {
tracing::error!(
operation = $operation,
error = %$error,
$($field)*,
"Operation failed"
);
};
}
#[macro_export]
macro_rules! trace_message {
($protocol:expr, $direction:expr) => {
tracing::debug_span!(
"message",
protocol = $protocol,
direction = $direction,
)
};
($protocol:expr, $direction:expr, $($field:tt)*) => {
tracing::debug_span!(
"message",
protocol = $protocol,
direction = $direction,
$($field)*
)
};
}
#[macro_export]
macro_rules! trace_connection {
($protocol:expr, $event:expr) => {
tracing::info!(
protocol = $protocol,
event = $event,
"Connection event"
);
};
($protocol:expr, $event:expr, $($field:tt)*) => {
tracing::info!(
protocol = $protocol,
event = $event,
$($field)*,
"Connection event"
);
};
}
#[macro_export]
macro_rules! trace_state_change {
($component:expr, $from:expr, $to:expr) => {
tracing::info!(
component = $component,
from_state = $from,
to_state = $to,
"State changed"
);
};
($component:expr, $from:expr, $to:expr, $($field:tt)*) => {
tracing::info!(
component = $component,
from_state = $from,
to_state = $to,
$($field)*,
"State changed"
);
};
}
#[macro_export]
macro_rules! trace_metric {
($name:expr, $value:expr) => {
tracing::debug!(
metric_name = $name,
metric_value = $value,
"Metric observation"
);
};
($name:expr, $value:expr, $($field:tt)*) => {
tracing::debug!(
metric_name = $name,
metric_value = $value,
$($field)*,
"Metric observation"
);
};
}
#[macro_export]
macro_rules! trace_tick {
($tick_num:expr) => {
tracing::trace_span!(
"tick",
tick = $tick_num,
)
};
($tick_num:expr, $($field:tt)*) => {
tracing::trace_span!(
"tick",
tick = $tick_num,
$($field)*
)
};
}
#[macro_export]
macro_rules! trace_enter {
($name:expr) => {
tracing::debug!(function = $name, "Entering");
};
($name:expr, $($field:tt)*) => {
tracing::debug!(function = $name, $($field)*, "Entering");
};
}
#[macro_export]
macro_rules! trace_exit {
($name:expr) => {
tracing::debug!(function = $name, "Exiting");
};
($name:expr, $($field:tt)*) => {
tracing::debug!(function = $name, $($field)*, "Exiting");
};
}
#[cfg(test)]
mod tests {
#[test]
fn test_macros_compile() {
}
}