|
| 1 | +<!-- This is used on crates.io --> |
| 2 | + |
1 | 3 |  |
2 | 4 |
|
3 | 5 | [](https://docs.rs/autometrics) |
4 | 6 | [](https://crates.io/crates/autometrics) |
5 | 7 | [](https://discord.gg/kHtwcH8As9) |
6 | 8 |
|
7 | | -Autometrics is an observability micro-framework built for developers. |
| 9 | +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 Prometheus queries to help you identify and debug issues in production. |
8 | 10 |
|
9 | | -The Rust library provides a macro that makes it easy to instrument any function with the most useful metrics: request rate, error rate, and latency. Autometrics uses instrumented function names to generate Prometheus queries so you don’t need to hand-write complicated PromQL. |
| 11 | +## Features |
10 | 12 |
|
11 | | -To make it easy for you to spot and debug issues in production, Autometrics inserts links to live charts directly into each function’s doc comments and provides dashboards that work out of the box. It also enables you to create powerful alerts based on Service-Level Objectives (SLOs) directly in your source code. Lastly, Autometrics writes queries that correlate your software’s version info with anomalies in the metrics to help you quickly identify commits that introduced bugs or latency. |
| 13 | +- ✨ [`#[autometrics]`](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html) macro instruments any function or `impl` block to track the [most useful metrics](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html#generated-metrics) |
| 14 | +- 💡 Writes Prometheus queries so you can understand the data generated without knowing PromQL |
| 15 | +- 🔗 Injects links to live Prometheus charts directly into each function's doc comments |
| 16 | +- [🔍 Identify commits](https://docs.rs/autometrics/latest/autometrics/#build_info-metric-labels) that introduced errors or increased latency |
| 17 | +- [🚨 Define alerts](https://docs.rs/autometrics/latest/autometrics/objectives/index.html) using SLO best practices directly in your source code |
| 18 | +- [📊 Grafana dashboards](https://github.com/autometrics-dev/autometrics-shared#dashboards) work out of the box to visualize the performance of instrumented functions & SLOs |
| 19 | +- [⚙️ 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)) |
| 20 | +- [📍 Attach exemplars](https://docs.rs/autometrics/latest/autometrics/exemplars/index.html) to connect metrics with traces |
| 21 | +- ⚡ Minimal runtime overhead |
| 22 | + |
| 23 | +See [autometrics.dev](https://docs.autometrics.dev/) for more details on the ideas behind autometrics. |
12 | 24 |
|
13 | 25 | ## Example Axum App |
14 | 26 |
|
@@ -40,91 +52,15 @@ pub async fn main() { |
40 | 52 | } |
41 | 53 | ``` |
42 | 54 |
|
43 | | -## Features |
44 | | - |
45 | | -- ✨ [`#[autometrics]`](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html) macro instruments any function or `impl` block to track the [most useful metrics](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html#generated-metrics) |
46 | | -- 💡 Writes Prometheus queries so you can understand the data generated without knowing PromQL |
47 | | -- 🔗 Injects links to live Prometheus charts directly into each function's doc comments |
48 | | -- [🔍 Identify commits](#identifying-commits-that-introduced-problems) that introduced errors or increased latency |
49 | | -- [🚨 Define alerts](https://docs.rs/autometrics/latest/autometrics/objectives/index.html) using SLO best practices directly in your source code |
50 | | -- [📊 Grafana dashboards](https://github.com/autometrics-dev#5-configuring-prometheus) work out of the box to visualize the performance of instrumented functions & SLOs |
51 | | -- [⚙️ Configurable](#metrics-libraries) 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)) |
52 | | -- [📍 Attach exemplars](https://docs.rs/autometrics/latest/autometrics/exemplars/index.html) to connect metrics with traces |
53 | | -- ⚡ Minimal runtime overhead |
54 | | - |
55 | | -See [Why Autometrics?](https://github.com/autometrics-dev#4-why-autometrics) for more details on the ideas behind autometrics. |
56 | | - |
57 | | -## Identifying commits that introduced problems |
58 | | - |
59 | | -Autometrics makes it easy to [spot versions and commits that introduce errors or latency](https://fiberplane.com/blog/autometrics-rs-0-4-spot-commits-that-introduce-errors-or-slow-down-your-application). |
60 | | - |
61 | | -It produces a `build_info` metric and uses the following labels to expose the version info of your app to Prometheus: |
62 | | - |
63 | | -| Label | Compile-Time Environment Variables | Default | |
64 | | -|---|---|---| |
65 | | -| `version` | `AUTOMETRICS_VERSION` or `CARGO_PKG_VERSION` | `CARGO_PKG_VERSION` (set by cargo by default) | |
66 | | -| `commit` | `AUTOMETRICS_COMMIT` or `VERGEN_GIT_COMMIT` | `""` | |
67 | | -| `branch` | `AUTOMETRICS_BRANCH` or `VERGEN_GIT_BRANCH` | `""` | |
68 | | - |
69 | | -### (Optional) Using [`vergen`](https://crates.io/crates/vergen) to set the Git details |
70 | | - |
71 | | -```toml |
72 | | -# Cargo.toml |
73 | | - |
74 | | -[build-dependencies] |
75 | | -vergen = { version = "8.1", features = ["git", "gitcl"] } |
76 | | -``` |
77 | | - |
78 | | -```rust |
79 | | -// build.rs |
80 | | -fn main() { |
81 | | - vergen::EmitBuilder::builder() |
82 | | - .git_sha(true) |
83 | | - .git_branch() |
84 | | - .emit() |
85 | | - .expect("Unable to generate build info"); |
86 | | -} |
87 | | -``` |
88 | | - |
89 | | - |
90 | | -## Configuring Autometrics |
91 | | - |
92 | | -### Custom Prometheus URL |
93 | | - |
94 | | -Autometrics inserts Prometheus query links into function documentation. By default, the links point to `http://localhost:9090` but you can configure it to use a custom URL using an environment variable in your `build.rs` file: |
95 | | - |
96 | | -```rust |
97 | | -// build.rs |
98 | | - |
99 | | -fn main() { |
100 | | - // Reload Rust analyzer after changing the Prometheus URL to regenerate the links |
101 | | - let prometheus_url = "https://your-prometheus-url.example"; |
102 | | - println!("cargo:rustc-env=PROMETHEUS_URL={prometheus_url}"); |
103 | | -} |
104 | | -``` |
105 | | - |
106 | | -### Feature flags |
107 | | - |
108 | | -- `prometheus-exporter` - exports a Prometheus metrics collector and exporter (compatible with any of the [Metrics backends](#metrics-backends)) |
109 | | -- `custom-objective-latency` - by default, Autometrics only supports a fixed set of latency thresholds for objectives. Enable this to use custom latency thresholds. Note, however, that the custom latency **must** match one of the buckets configured for your histogram or the alerts will not work. This is not currently compatible with the `prometheus` or `prometheus-exporter` feature. |
110 | | -- `custom-objective-percentile` by default, Autometrics only supports a fixed set of objective percentiles. Enable this to use a custom percentile. Note, however, that using custom percentiles requires generating a different recording and alerting rules file using the CLI + Sloth (see [here](https://github.com/autometrics-dev/autometrics-rs/tree/main/autometrics-cli)). |
111 | | - |
112 | | -#### Metrics backends |
113 | | - |
114 | | -**Required:** Configure which library autometrics will use to produce metrics by using one of the following feature flags: |
115 | | - |
116 | | -> **Note** |
117 | | -> |
118 | | -> If you are **not** using the `prometheus-exporter`, you must ensure that you are using the exact same version of the metrics library as `autometrics` (and it must come from `crates.io` rather than git or another source). If not, the autometrics metrics will not appear in your exported metrics. |
| 55 | +## Quickstart |
119 | 56 |
|
120 | | -- `opentelemetry` - use the [opentelemetry](https://crates.io/crates/opentelemetry) crate for producing metrics. |
121 | | -- `metrics` - use the [metrics](https://crates.io/crates/metrics) crate for producing metrics |
122 | | -- `prometheus` - use the [prometheus](https://crates.io/crates/prometheus) crate for producing metrics |
123 | | -- `prometheus-client` - use the official [prometheus-client](https://crates.io/crates/prometheus-client) crate for producing metrics |
| 57 | +See the [Github repo README](https://github.com/autometrics-dev/autometrics-rs#quickstart) to quickly add `autometrics` to your project. |
124 | 58 |
|
125 | | -#### Exemplars (for integrating metrics with traces) |
| 59 | +## Contributing |
126 | 60 |
|
127 | | -See the [exemplars module docs](https://docs.rs/autometrics/latest/autometrics/exemplars/index.html) for details about these features. Currently only supported with the `prometheus-client` backend. |
| 61 | +Issues, feature suggestions, and pull requests are very welcome! |
128 | 62 |
|
129 | | -- `exemplars-tracing` - extract arbitrary fields from `tracing::Span`s |
130 | | -- `exemplars-tracing-opentelemetry` - extract the `trace_id` and `span_id` from the `opentelemetry::Context`, which is attached to `tracing::Span`s by the `tracing-opentelemetry` crate |
| 63 | +If you are interested in getting involved: |
| 64 | +- Join the conversation on [Discord](https://discord.gg/9eqGEs56UB) |
| 65 | +- Ask questions and share ideas in the [Github Discussions](https://github.com/orgs/autometrics-dev/discussions) |
| 66 | +- Take a look at the overall [Autometrics Project Roadmap](https://github.com/orgs/autometrics-dev/projects/1) |
0 commit comments