Telemetry automatically creates tables when data is logged. In the following example, we log some Uber ride data to a table called uber_rides. Telemetry will automatically create this table and its corresponding schema with columns: city, price, and timestamp.
You can query the data using SQL through the query API:
fnquery_data(telemetry:&Telemetry) ->Result<(), Box<dyn std::error::Error>> {let query =" SELECT city, AVG(price) AS average_price FROM uber_rides GROUP BY city ";let query_response = telemetry.query(query)?;println!("Query response: {:?}", query_response);Ok(())}
Example Main Function
Here is an example of how you can integrate logging and querying data in your main function:
fnmain() {letmut telemetry =Telemetry::new(); telemetry.init("YOUR_API_KEY".to_string()); // Replace with your actual API keyifletErr(e) =log_data(&telemetry) {eprintln!("Error logging data: {}", e); }ifletErr(e) =query_data(&telemetry) {eprintln!("Error querying data: {}", e); }}
This documentation provides an overview of how to set up and use the Rust SDK for Telemetry, with examples of logging and querying data.