Skip to content
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@
[![Crates.io](https://img.shields.io/crates/v/autometrics.svg)](https://crates.io/crates/autometrics)
[![Discord Shield](https://discordapp.com/api/guilds/950489382626951178/widget.png?style=shield)](https://discord.gg/kHtwcH8As9)

Autometrics provides a macro that makes it easy to instrument any function with the most useful metrics: request rate, error rate, and latency. It then uses the instrumented function names to generate powerful Prometheus queries to help you identify and debug issues in production.
Autometrics provides a macro that makes it trivial to instrument any function with the most useful metrics: request rate, error rate, and latency.

## Features
Autometrics then uses your function details to generate powerful Prometheus queries that help you identify and debug issues in production.

- ✨ [`#[autometrics]`](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html) macro instruments any function or `impl` block to track the [most useful metrics](https://github.com/autometrics-dev/autometrics-shared/blob/main/SPEC.md#metrics)
- 💡 Writes Prometheus queries so you can understand the data generated without knowing PromQL
It is a thin layer on top of existing Prometheus and OpenTelemetry libraries that produces standardized metrics and uses this standardization to give lots of benefits out of the box:

## Benefits

- [✨ `#[autometrics]`](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html) macro instruments any function or `impl` block to add useful metrics, without you having to think about what is worth tracking
- 💡 Writes Prometheus queries so you can understand your metrics without being a PromQL expert
- 🔗 Injects links to live Prometheus charts directly into each function's doc comments
- [🔍 Identify commits](https://docs.rs/autometrics/latest/autometrics/#identifying-faulty-commits-with-the-build_info-metric) that introduced errors or increased latency
- [📊 Grafana dashboards](https://github.com/autometrics-dev/autometrics-shared#dashboards) work without configuration to visualize the performance of functions & [SLOs](https://docs.rs/autometrics/latest/autometrics/objectives/index.html)
- 🔍 Correlates your code's version to help [identify commits](https://docs.rs/autometrics/latest/autometrics/#identifying-faulty-commits-with-the-build_info-metric) that introduced errors or latency
- ⚖️ Function-level metrics are granular without [exploding cardinality](https://blog.cloudflare.com/how-cloudflare-runs-prometheus-at-scale/#metrics-cardinality)
- 📏 Standardizing metrics across services and teams improves debugging
- [⚡ Minimal runtime overhead](#benchmarks)

## Advanced Features

- [🚨 Define alerts](https://docs.rs/autometrics/latest/autometrics/objectives/index.html) using SLO best practices directly in your source code
- [📊 Grafana dashboards](https://github.com/autometrics-dev/autometrics-shared#dashboards) work out of the box to visualize the performance of instrumented functions & SLOs
- [⚙️ Configurable](https://docs.rs/autometrics/latest/autometrics/#metrics-backends) metric collection library ([`opentelemetry`](https://crates.io/crates/opentelemetry), [`prometheus`](https://crates.io/crates/prometheus), [`prometheus-client`](https://crates.io/crates/prometheus-client) or [`metrics`](https://crates.io/crates/metrics))
- [📍 Attach exemplars](https://docs.rs/autometrics/latest/autometrics/exemplars/index.html) to connect metrics with traces
- ⚡ Minimal runtime overhead
- [⚙️ Configurable](https://docs.rs/autometrics/latest/autometrics/#metrics-backends) metric collection library ([`opentelemetry`](https://crates.io/crates/opentelemetry), [`prometheus`](https://crates.io/crates/prometheus), [`prometheus-client`](https://crates.io/crates/prometheus-client) or [`metrics`](https://crates.io/crates/metrics))

See [autometrics.dev](https://docs.autometrics.dev/) for more details on the ideas behind autometrics.

Expand All @@ -27,37 +36,10 @@ use autometrics::autometrics;

#[autometrics]
pub async fn create_user() {
// Now this function has metrics! 📈
// Now this function produces metrics! 📈
}
```

<details>
<summary>See an example of a PromQL query generated by Autometrics</summary>

<br />

_If your eyes glaze over when you see this, don't worry! Autometrics writes complex queries like this so you don't have to!_

```promql
(
sum by (function, module, commit, version) (
rate({__name__=~"function_calls(_count)?(_total)?",function="create_user",result="error"}[5m])
* on (instance, job) group_left (version, commit)
last_over_time(build_info[1s])
)
)
/
(
sum by (function, module, commit, version) (
rate({__name__=~"function_calls(_count)?(_total)?",function="create_user"}[5m])
* on (instance, job) group_left (version, commit)
last_over_time(build_info[1s])
)
)
```

</details>

Here is a demo of jumping from function docs to live Prometheus charts:

https://github.com/autometrics-dev/autometrics-rs/assets/3262610/966ed140-1d6c-45f3-a607-64797d5f0233
Expand All @@ -70,6 +52,24 @@ https://github.com/autometrics-dev/autometrics-rs/assets/3262610/966ed140-1d6c-4
```
2. Instrument your functions with the [`#[autometrics]`](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html) macro

```rust
use autometrics::autometrics;

#[autometrics]
pub async fn my_function() {
// Now this function produces metrics!
}

struct MyStruct;

#[autometrics]
impl MyStruct {
pub fn my_method() {
// This method produces metrics too!
}
}
```

<details>

<summary> Tip: Adding autometrics to all functions using the <a href="https://docs.rs/tracing/latest/tracing/instrument/trait.Instrument.html"><code>tracing::instrument</code></a> macro
Expand Down