
Metrics are a powerful and cost-efficient tool for understanding the health and performance of your code in production. But it's hard to decide what metrics to track and even harder to write queries to understand the data.
Autometrics provides a macro that makes it trivial to instrument any function with the most useful metrics: request rate, error rate, and latency. It standardizes these metrics and then generates powerful Prometheus queries based on your function details to help you quickly identify and debug issues in production.
Benefits
- ✨
#[autometrics]macro adds useful metrics to any function orimplblock, without you thinking about what metrics to collect - 💡 Generates powerful Prometheus queries to help quickly identify and debug issues in production
- 🔗 Injects links to live Prometheus charts directly into each function's doc comments
- 📊 Grafana dashboards work without configuration to visualize the performance of functions & SLOs
- 🔍 Correlates your code's version with metrics to help identify commits that introduced errors or latency
- 📏 Standardizes metrics across services and teams to improve debugging
- ⚖️ Function-level metrics provide useful granularity without exploding cardinality
- ⚡ Minimal runtime overhead
Advanced Features
- 🚨 Define alerts using SLO best practices directly in your source code
- 📍 Attach exemplars automatically to connect metrics with traces
- ⚙️ Configurable metric collection library (
opentelemetry,prometheus,prometheus-clientormetrics)
See autometrics.dev for more details on the ideas behind autometrics.
Example Axum App
Autometrics isn't tied to any web framework, but this shows how you can use the library in an Axum server.
use Error;
use ;
use ;
use Ipv4Addr;
use TcpListener;
// Instrument your functions with metrics
pub async
// Export the metrics to Prometheus
pub async
Quickstart
See the Github repo README to quickly add autometrics to your project.
Contributing
Issues, feature suggestions, and pull requests are very welcome!
If you are interested in getting involved:
- Join the conversation on Discord
- Ask questions and share ideas in the Github Discussions
- Take a look at the overall Autometrics Project Roadmap
