Macro attributes
macro_rules! attributes {
({ $($kvs:tt)* }) => { ... };
($($kvs:tt)*) => { ... };
}Expand description
Constructs a slice of KeyValue attributes.
This macro is primarily used when manually constructing spans.
§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"
);Span construction with attributes:
use veecle_telemetry::{Span, SpanContext, attributes};
let operation = "user_login";
let user_id = 456;
let span = Span::new(
"authentication",
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