use std::{env, thread, time::Duration}; use newrelic::App; fn main() { let license_key = env::var("NEW_RELIC_LICENSE_KEY").unwrap_or_else(|_| "example-license-key".to_string()); let app = App::new("my app", &license_key).expect("Could not create app"); // Start a web transaction and a segment let transaction = app .web_transaction("Transaction name") .expect("Could not start transaction"); let value = transaction.custom_segment("Segment name", "Segment category", |s| { // Interesting application code happens here thread::sleep(Duration::from_secs(1)); let expensive_val_1 = s.custom_nested("First nested segment", "Nested category", |_| { thread::sleep(Duration::from_secs(1)); 3 }); let expensive_val_2 = s.custom_nested("Second nested segment", "Nested category", |_| { thread::sleep(Duration::from_secs(1)); 2 }); expensive_val_1 * expensive_val_2 }); println!("{}", value); // Transaction ends automatically. // App is destroyed automatically. }