use std::{env, thread, time::Duration}; use newrelic::{App, Datastore, DatastoreParamsBuilder}; 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 segment_params = DatastoreParamsBuilder::new(Datastore::Postgres) .collection("people") .operation("select") .build() .expect("Invalid datastore segment parameters"); let value = transaction.datastore_segment(&segment_params, |_| { // Interesting application code happens here thread::sleep(Duration::from_secs(5)); 5 }); println!("{}", value); // Transaction ends automatically. // App is destroyed automatically. }