macro_rules! span {
($name:expr) => { ... };
($name:expr, $($key:expr => $value:expr),+ $(,)?) => { ... };
}Expand description
Creates a new span with the given name and fields.
The span is active until the returned guard is dropped. All log messages within the span will include the span’s context information.
§Syntax
ⓘ
span!(name)
span!(name, key1 => value1)
span!(name, key1 => value1, key2 => value2, ...)§Examples
use traccia::{span, info, init_default};
init_default();
fn process_request(user_id: u64) {
let _span = span!("request", "user_id" => user_id);
info!("Processing request");
// Logs: [INFO] Processing request [request: user_id=42]
}use traccia::{span, info, init_default};
init_default();
fn handle_connection(conn_id: u32, ip: &str) {
let _span = span!("connection", "id" => conn_id, "ip" => ip);
info!("Connection established");
// Logs: [INFO] Connection established [connection: id=123, ip=127.0.0.1]
}