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.
Query Some Data
You can query the data using SQL through the query API:
Example Main Function
Here is an example of how you can integrate logging and querying data in your main function:
This documentation provides an overview of how to set up and use the Rust SDK for Telemetry, with examples of logging and querying data.
fn log_data(telemetry: &Telemetry) -> Result<(), Box<dyn std::error::Error>> {
let data = json!({
"city": "paris",
"price": 42,
"timestamp": Utc::now().to_rfc3339()
});
let response = telemetry.log("uber_rides", &data)?;
println!("Log response: {:?}", response);
Ok(())
}
fn query_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(())
}
fn main() {
let mut telemetry = Telemetry::new();
telemetry.init("YOUR_API_KEY".to_string()); // Replace with your actual API key
if let Err(e) = log_data(&telemetry) {
eprintln!("Error logging data: {}", e);
}
if let Err(e) = query_data(&telemetry) {
eprintln!("Error querying data: {}", e);
}
}