1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
//! Macros for structured logging and telemetry.
//!
//! This module provides convenient macros for creating spans, adding events, and logging
//! messages with various severity levels.
//! The macros provide a more ergonomic interface compared to the lower-level functions and handle attribute creation
//! automatically.
//!
//! # Span Creation
//!
//! - `span!`: Creates a new span with optional attributes
//! - `event!`: Adds an event to the current span
//!
//! # Logging Macros
//!
//! - `log!`: Generic logging macro that accepts a severity level
//! - `trace!`: Logs trace-level messages (most verbose)
//! - `debug!`: Logs debug-level messages
//! - `info!`: Logs informational messages
//! - `warn!`: Logs warning messages
//! - `error!`: Logs error messages
//! - `fatal!`: Logs fatal error messages
//!
//! # Attribute Handling
//!
//! - `attributes!`: Creates a slice of key-value attributes
//! - `attribute!`: Creates a single key-value attribute
//!
//! All macros support flexible attribute syntax for adding contextual information.
/// Creates a new span.
///
/// A span represents a unit of work or operation that has a beginning and end.
/// It can contain attributes that provide additional context about the operation.
///
/// # Examples
///
/// ```rust
/// use veecle_telemetry::span;
///
/// let span = span!("database_query");
/// ```
///
/// ```rust
/// use veecle_telemetry::span;
///
/// let user_id = 123;
/// let table_name = "users";
/// let span =
/// span!("database_query", user_id, table = table_name, "operation" = "select");
/// ```
/// Creates a new root span.
///
/// See [span].
///
/// # Examples
///
/// ```rust
/// use veecle_telemetry::root_span;
///
/// let span = root_span!("request");
/// ```
/// Adds an event to the current span.
///
/// Events are timestamped occurrences that happen during the execution of a span.
/// They can include additional context through attributes.
///
/// # Examples
///
/// Add a simple event:
/// ```rust
/// use veecle_telemetry::event;
///
/// event!("cache_miss");
/// ```
///
/// Add an event with attributes:
/// ```rust
/// use veecle_telemetry::event;
///
/// let key = "user:123";
/// let cache_type = "redis";
/// event!("cache_miss", key = key, cache_type = cache_type, "retry_count" = 3);
/// ```
/// Logs a message with the specified severity level.
///
/// This is the base logging macro that other severity-specific macros build upon.
/// It allows you to specify the severity level and optional attributes.
///
/// # Examples
///
/// Log a simple message:
/// ```rust
/// use veecle_telemetry::log;
/// use veecle_telemetry::protocol::Severity;
///
/// log!(Severity::Info, "Application started");
/// ```
///
/// Log a message with attributes:
/// ```rust
/// use veecle_telemetry::log;
/// use veecle_telemetry::protocol::Severity;
///
/// let port = 8080;
/// let version = "1.0.0";
/// log!(Severity::Info, "Server listening", port = port, version = version, "protocol" = "HTTP");
/// ```
/// Logs a trace-level message.
///
/// Trace messages are used for very detailed debugging information,
/// typically only enabled during development or deep troubleshooting.
///
/// # Examples
///
/// Simple trace message:
/// ```rust
/// use veecle_telemetry::trace;
///
/// trace!("Entering function");
/// ```
///
/// Trace message with context:
/// ```rust
/// use veecle_telemetry::trace;
///
/// let function_name = "process_request";
/// let request_id = "req-123";
/// trace!("Function entry", function = function_name, request_id = request_id);
/// ```
/// Logs a debug-level message.
///
/// Debug messages provide detailed information about the program's execution,
/// useful for diagnosing issues during development and testing.
///
/// # Examples
///
/// Simple debug message:
/// ```rust
/// use veecle_telemetry::debug;
///
/// debug!("Processing user request");
/// ```
///
/// Debug message with variables:
/// ```rust
/// use veecle_telemetry::debug;
///
/// let user_id = 456;
/// let action = "login";
/// debug!("User action processed", user_id = user_id, action = action, "success" = true);
/// ```
/// Logs an info-level message.
///
/// Info messages provide general information about the program's execution,
/// suitable for normal operational logging.
///
/// # Examples
///
/// Simple info message:
/// ```rust
/// use veecle_telemetry::info;
///
/// info!("Service started successfully");
/// ```
///
/// Info message with metadata:
/// ```rust
/// use veecle_telemetry::info;
///
/// let service_name = "web-server";
/// let version = "2.1.0";
/// info!(
/// "Service initialization complete",
/// service = service_name,
/// version = version,
/// "startup_time_ms" = 1250
/// );
/// ```
/// Logs a warning-level message.
///
/// Warning messages indicate potential issues or unusual conditions
/// that don't prevent the program from continuing but should be noted.
///
/// # Examples
///
/// Simple warning message:
/// ```rust
/// use veecle_telemetry::warn;
///
/// warn!("Rate limit approaching");
/// ```
///
/// Warning with context:
/// ```rust
/// use veecle_telemetry::warn;
///
/// let current_requests = 950;
/// let limit = 1000;
/// warn!(
/// "High request rate detected",
/// current_requests = current_requests,
/// limit = limit,
/// "utilization_percent" = 95
/// );
/// ```
/// Logs an error-level message.
///
/// Error messages indicate serious problems that have occurred
/// but allow the program to continue running.
///
/// # Examples
///
/// Simple error message:
/// ```rust
/// use veecle_telemetry::error;
///
/// error!("Database connection failed");
/// ```
///
/// Error with details:
/// ```rust
/// use veecle_telemetry::error;
///
/// let db_host = "localhost:5432";
/// let error_code = 1001;
/// error!(
/// "Database operation failed",
/// host = db_host,
/// error_code = error_code,
/// "retry_attempted" = true
/// );
/// ```
/// Logs a fatal-level message.
///
/// Fatal messages indicate critical errors that will likely cause
/// the program to terminate or become unusable.
///
/// # Examples
///
/// Simple fatal message:
/// ```rust
/// use veecle_telemetry::fatal;
///
/// fatal!("Critical system failure");
/// ```
///
/// Fatal error with context:
/// ```rust
/// use veecle_telemetry::fatal;
///
/// let component = "memory_allocator";
/// let error_type = "out_of_memory";
/// fatal!(
/// "System component failure",
/// component = component,
/// error_type = error_type,
/// "available_memory_mb" = 0
/// );
/// ```
/// 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 name
/// - `identifier` - Uses the identifier as both key and value
/// - `field.subfield` - Simple dot notation for field access
///
/// # Examples
///
/// Basic usage with mixed attribute types:
/// ```rust
/// 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:
/// ```rust
/// 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:
/// ```rust
/// 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:
/// ```rust
/// use veecle_telemetry::attributes;
/// use veecle_telemetry::value::KeyValue;
///
/// let attrs: &[KeyValue] = attributes!(); // Creates an empty slice
/// ```
/// Constructs a single attribute `KeyValue` pair.