{"id":13576217,"url":"https://github.com/autometrics-dev/autometrics-rs","last_synced_at":"2025-05-14T00:06:37.325Z","repository":{"id":65527574,"uuid":"588111675","full_name":"autometrics-dev/autometrics-rs","owner":"autometrics-dev","description":"Easily add metrics to your code that actually help you spot and debug issues in production. Built on Prometheus and OpenTelemetry.","archived":false,"fork":false,"pushed_at":"2024-10-21T22:52:29.000Z","size":847,"stargazers_count":817,"open_issues_count":14,"forks_count":31,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-12T23:11:41.708Z","etag":null,"topics":["metrics","monitoring","observability","opentelemetry","prometheus","rust","telemetry","tracing"],"latest_commit_sha":null,"homepage":"https://autometrics.dev","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/autometrics-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-12T10:58:47.000Z","updated_at":"2025-05-12T18:41:34.000Z","dependencies_parsed_at":"2023-06-27T16:34:00.566Z","dependency_job_id":"4e5b0a2d-0ad5-45a7-b2a0-12060ab58962","html_url":"https://github.com/autometrics-dev/autometrics-rs","commit_stats":{"total_commits":169,"total_committers":17,"mean_commits":9.941176470588236,"dds":0.485207100591716,"last_synced_commit":"8b761f78c77c8e20697c7a739c2889a7689640ca"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autometrics-dev%2Fautometrics-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autometrics-dev%2Fautometrics-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autometrics-dev%2Fautometrics-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autometrics-dev%2Fautometrics-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autometrics-dev","download_url":"https://codeload.github.com/autometrics-dev/autometrics-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043539,"owners_count":22004969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["metrics","monitoring","observability","opentelemetry","prometheus","rust","telemetry","tracing"],"created_at":"2024-08-01T15:01:08.056Z","updated_at":"2025-05-14T00:06:37.308Z","avatar_url":"https://github.com/autometrics-dev.png","language":"Rust","funding_links":[],"categories":["Rust","Tools"],"sub_categories":[],"readme":"![GitHub_headerImage](https://user-images.githubusercontent.com/3262610/221191767-73b8a8d9-9f8b-440e-8ab6-75cb3c82f2bc.png)\n\n## NOTE: Autometrics is no longer actively maintained.\n\n[![Documentation](https://docs.rs/autometrics/badge.svg)](https://docs.rs/autometrics)\n[![Crates.io](https://img.shields.io/crates/v/autometrics.svg)](https://crates.io/crates/autometrics)\n[![Discord Shield](https://discordapp.com/api/guilds/950489382626951178/widget.png?style=shield)](https://discord.gg/kHtwcH8As9)\n\nMetrics 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.\n\nAutometrics 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.\n\n## Benefits\n\n- [✨ `#[autometrics]`](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html) macro adds useful metrics to any function or `impl` block, without you thinking about what metrics to collect\n- 💡 Generates powerful Prometheus queries to help quickly identify and debug issues in production\n- 🔗 Injects links to live Prometheus charts directly into each function's doc comments\n- [📊 Grafana dashboards](https://github.com/autometrics-dev/autometrics-shared#dashboards) work without configuration to visualize the performance of functions \u0026 [SLOs](https://docs.rs/autometrics/latest/autometrics/objectives/index.html)\n- 🔍 Correlates your code's version with metrics to help identify commits that introduced errors or latency\n- 📏 Standardizes metrics across services and teams to improve debugging\n- ⚖️ Function-level metrics provide useful granularity without exploding cardinality\n- [⚡ Minimal runtime overhead](#benchmarks)\n\n## Advanced Features\n\n- [🚨 Define alerts](https://docs.rs/autometrics/latest/autometrics/objectives/index.html) using SLO best practices directly in your source code\n- [📍 Attach exemplars](https://docs.rs/autometrics/latest/autometrics/exemplars/index.html) automatically to connect metrics with traces\n- [⚙️ 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))\n\nSee [autometrics.dev](https://docs.autometrics.dev/) for more details on the ideas behind autometrics.\n\n# Example + Demo\n\n```rust\nuse autometrics::autometrics;\n\n#[autometrics]\npub async fn create_user() {\n  // Now this function produces metrics! 📈\n}\n```\n\nHere is a demo of jumping from function docs to live Prometheus charts:\n\nhttps://github.com/autometrics-dev/autometrics-rs/assets/3262610/966ed140-1d6c-45f3-a607-64797d5f0233\n\n## Quickstart\n\n1. Add `autometrics` to your project:\n    ```sh\n    cargo add autometrics --features=prometheus-exporter\n    ```\n2. Instrument your functions with the [`#[autometrics]`](https://docs.rs/autometrics/latest/autometrics/attr.autometrics.html) macro\n\n    ```rust\n    use autometrics::autometrics;\n\n    // Just add the autometrics annotation to your functions\n    #[autometrics]\n    pub async fn my_function() {\n      // Now this function produces metrics!\n    }\n\n    struct MyStruct;\n\n    // You can also instrument whole impl blocks\n    #[autometrics]\n    impl MyStruct {\n      pub fn my_method() {\n        // This method produces metrics too!\n      }\n    }\n    ```\n\n\n    \u003cdetails\u003e\n\n    \u003csummary\u003e Tip: Adding autometrics to all functions using the \u003ca href=\"https://docs.rs/tracing/latest/tracing/instrument/trait.Instrument.html\"\u003e\u003ccode\u003etracing::instrument\u003c/code\u003e\u003c/a\u003e macro\n    \u003c/summary\u003e\n      \u003cbr /\u003e\n\n      You can use a search and replace to add autometrics to all functions instrumented with `tracing::instrument`.\n\n      Replace:\n      ```rust\n      #[instrument]\n      ```\n      With:\n      ```rust\n      #[instrument]\n      #[autometrics]\n      ```\n\n      And then let Rust Analyzer tell you which files you need to add `use autometrics::autometrics` at the top of.\n\n    \u003c/details\u003e\n    \u003cdetails\u003e\n\n    \u003csummary\u003e Tip: Adding autometrics to all \u003ccode\u003epub\u003c/code\u003e functions (not necessarily recommended 😅)\n    \u003c/summary\u003e\n      \u003cbr /\u003e\n\n      You can use a search and replace to add autometrics to all public functions. Yes, this is a bit nuts.\n\n      Use a regular expression search to replace:\n      ```\n      (pub (?:async)? fn.*)\n      ```\n\n      With:\n      ```\n      #[autometrics]\n      $1\n      ```\n\n      And then let Rust Analyzer tell you which files you need to add `use autometrics::autometrics` at the top of.\n\n    \u003c/details\u003e\n\n3. Export the metrics for Prometheus\n\n    \u003cdetails\u003e\n\n      \u003csummary\u003e\n      For projects not currently using Prometheus metrics\n      \u003c/summary\u003e\n\n      \u003cbr /\u003e\n\n      Autometrics includes optional functions to help collect and prepare metrics to be collected by Prometheus.\n\n      In your `main` function, initialize the `prometheus_exporter`:\n\n      ```rust\n      pub fn main() {\n        prometheus_exporter::init();\n        // ...\n      }\n      ```\n\n      And create a route on your API (probably mounted under `/metrics`) that returns the following:\n\n      ```rust\n      use autometrics::prometheus_exporter::{self, PrometheusResponse};\n\n      /// Export metrics for Prometheus to scrape\n      pub fn get_metrics() -\u003e PrometheusResponse {\n        prometheus_exporter::encode_http_response()\n      }\n      ```\n\n      \u003c/details\u003e\n\n      \u003cdetails\u003e\n\n      \u003csummary\u003e\n      For projects already using custom Prometheus metrics\n      \u003c/summary\u003e\n\n      \u003cbr /\u003e\n\n      [Configure `autometrics`](https://docs.rs/autometrics/latest/autometrics/#metrics-libraries) to use the same underlying metrics library you use with the feature flag corresponding to the crate and version you are using.\n\n      ```toml\n      [dependencies]\n      autometrics = {\n        version = \"*\",\n        features = [\"prometheus-0_13\"],\n        default-features = false\n      }\n      ```\n\n      The `autometrics` metrics will be produced alongside yours.\n\n      \u003e **Note**\n      \u003e\n      \u003e You must ensure that you are using the exact same version of the library as `autometrics`. If not, the `autometrics` metrics will not appear in your exported metrics.\n      \u003e This is because Cargo will include both versions of the crate and the global statics used for the metrics registry will be different.\n\n      You do not need to use the Prometheus exporter functions this library provides (you can leave out the `prometheus-exporter` feature flag) and you do not need a separate endpoint for autometrics' metrics.\n\n      \u003c/details\u003e\n\n  4. Run Prometheus locally with the [Autometrics CLI](https://docs.autometrics.dev/local-development#getting-started-with-am) or [configure it manually](https://github.com/autometrics-dev#5-configuring-prometheus) to scrape your metrics endpoint\n  5. (Optional) If you have Grafana, import the [Autometrics dashboards](https://github.com/autometrics-dev/autometrics-shared#dashboards) for an overview and detailed view of the function metrics\n\n## [API Docs](https://docs.rs/autometrics)\n\n## [Examples](./examples)\n\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/autometrics-dev/autometrics-rs)\n\nTo see autometrics in action:\n\n1. Install [prometheus](https://prometheus.io/download/) locally or download the [Autometrics CLI](https://docs.autometrics.dev/local-development#getting-started-with-am) which will install and configure Prometheus for you locally.\n2. Run the [complete example](./examples/full-api):\n\n    ```shell\n    cargo run -p example-full-api\n    ```\n\n3. Hover over the [function names](./examples/full-api/src/routes.rs#L13) to see the generated query links\n   (like in the image above) and view the Prometheus charts\n\n## Benchmarks\n\nUsing each of the following metrics libraries, tracking metrics with the `autometrics` macro adds approximately:\n- `prometheus-0_13`: 140-150 nanoseconds\n- `prometheus-client-0_21`: 150-250 nanoseconds\n- `metrics-0_21`: 550-650 nanoseconds\n- `opentelemetry-0_20`: 1700-2100 nanoseconds\n\nThese were calculated on a 2021 MacBook Pro with the M1 Max chip and 64 GB of RAM.\n\nTo run the benchmarks yourself, run the following command, replacing `BACKEND` with the metrics library of your choice:\n```sh\ncargo bench --features prometheus-exporter,BACKEND\n```\n\n## Contributing\n\nIssues, feature suggestions, and pull requests are very welcome!\n\nIf you are interested in getting involved:\n- Join the conversation on [Discord](https://discord.gg/9eqGEs56UB)\n- Ask questions and share ideas in the [Github Discussions](https://github.com/orgs/autometrics-dev/discussions)\n- Take a look at the overall [Autometrics Project Roadmap](https://github.com/orgs/autometrics-dev/projects/1)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautometrics-dev%2Fautometrics-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautometrics-dev%2Fautometrics-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautometrics-dev%2Fautometrics-rs/lists"}