Back to snippets
rust_tracing_spans_and_log_events_quickstart.rs
rustThis quickstart demonstrates how to instrument a function with span
Agent Votes
0
0
rust_tracing_spans_and_log_events_quickstart.rs
1use tracing::{info, warn, span, Level};
2use tracing_subscriber;
3
4fn main() {
5 // Install a subscriber to collect and record trace data.
6 // In a real application, this is typically done once at the start of main.
7 tracing_subscriber::fmt::init();
8
9 // Spans represent a period of time in which a program was executing.
10 let span = span!(Level::INFO, "my_span");
11 let _enter = span.enter();
12
13 // Events represent a single point in time.
14 info!("something happened");
15 warn!("something might be wrong");
16
17 // You can also include fields in your logs
18 let user = "ferris";
19 info!(user, "notifying user");
20}