Macro attributes
macro_rules! attributes {
(@ { $(,)* $($val:expr),* $(,)* }, $(,)*) => { ... };
(@ { $(,)* $($out:expr),* }, $($key:ident).+, $($rest:tt)+) => { ... };
(@ { $(,)* $($out:expr),* }, $($key:ident)+ = $value:expr, $($rest:tt)+) => { ... };
(@ { $(,)* $($out:expr),* }, $key:literal = $value:expr, $($rest:tt)+) => { ... };
(@ { $(,)* $($out:expr),* }, $($key:ident).+) => { ... };
(@ { $(,)* $($out:expr),* }, $($key:ident)+ = $value:expr) => { ... };
(@ { $(,)* $($out:expr),* }, $key:literal = $value:expr) => { ... };
({ $($kvs:tt)+ }) => { ... };
($($kvs:tt)+) => { ... };
($(,)?) => { ... };
}
Expand description
Constructs a slice of KeyValue
attributes.
This macro is primarily used when manually constructing spans, such as root spans that don’t have a convenience macro.
§Syntax
The macro supports several attribute formats:
identifier = value
- Uses the identifier as the key name"literal" = value
- Uses the literal string as the key nameidentifier
- Uses the identifier as both key and valuefield.subfield
- Simple dot notation for field access
§Examples
Basic usage with mixed attribute types:
use veecle_telemetry::attributes;
let user_id = 123;
let service_name = "auth-service";
let attrs = attributes!(user_id = user_id, "service" = service_name, "version" = "1.0.0");
Using identifiers as both key and value:
use veecle_telemetry::attributes;
let database = "postgresql";
let timeout = 30;
let attrs = attributes!(
database, // equivalent to database = database
timeout = timeout,
"connection_pool" = "primary"
);
Root span construction with attributes:
use veecle_telemetry::{Span, SpanContext, attributes};
let operation = "user_login";
let user_id = 456;
let span = Span::root(
"authentication",
SpanContext::generate(),
attributes!(operation = operation, user_id = user_id, "security_level" = "high"),
);
Empty attributes:
use veecle_telemetry::attributes;
use veecle_telemetry::value::KeyValue;
let attrs: &[KeyValue] = attributes!(); // Creates an empty slice