A command that lists all functions that have the "autometrics" annotation.
The aim is to use this binary as a quick static analyzer that returns from a codebase the complete list of functions that are annotated to be autometricized.
The analysis is powered by Tree-sitter, and all the specific logic is contained in TS queries that are specific for each language implementation.
Given this (edited for simplicity) example file, where some functions have the autometrics annotation:
```rust use autometrics::{autometrics, encodeglobalmetrics}; use axum::{http::StatusCode, response::IntoResponse, routing::get, Router};
/// This is a simple endpoint that never errors
pub async fn get_index() -> &'static str { "Hello, World!" }
/// This is a function that returns an error ~50% of the time
pub async fn getrandomerror() -> Result<(), ()> {
let should_error = random::
sleep_random_duration().await;
if should_error {
Err(())
} else {
Ok(())
}
}
/// This function doesn't return a Result, but we can determine whether
/// we want to consider it a success or not by passing a function to the ok_if
parameter.
pub async fn routethatreturnsintoresponse() -> impl IntoResponse { (StatusCode::OK, "Hello, World!") }
/// Determine whether the response was a success or not
fn issuccess
/// This isn't autometricized pub async fn get_metrics() -> (StatusCode, String) { // ... }
pub async fn main() { // ... server .serve(app.intomakeservice()) .await .expect("Error starting example API server"); }
pub async fn generaterandomtraffic() { let client = reqwest::Client::new(); loop { //... } } ```
We'll get
```console $ am_list src/main.rs
All functions in src/main.rs: getindex getrandomerror routethatreturnsintoresponse issuccess getmetrics main generaterandom_traffic
Autometrics functions in src/main.rs: getindex getrandomerror routethatreturnsinto_response ```