Library / SDK
metrics-rs/metrics avatar
metrics-rs/metrics

metrics-rs/metrics: A Rust Metrics Facade and Exporter Ecosystem

A metrics ecosystem for Rust.

1,494 stars228 forksRustMIT

At a glance

What is it?
metrics-rs/metrics provides a lightweight, protocol-agnostic facade for recording application metrics in Rust, with companion crates for Prometheus, TCP, tracing context, and metric utilities. It suits library authors who want instrumentation without committing to a particular backend and application teams that need to export the resulting measurements.
Who is it for?
Adopt metrics-rs/metrics when a Rust library needs a backend-neutral instrumentation API, or when an application team wants to choose its own export path. Do not adopt it alone if you require a complete dashboard, storage system, or alert workflow, because this repository supplies the facade and selected exporters rather than an analysis backend.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 7 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

Why the metrics Facade Exists

metrics addresses a specific gap in Rust observability: application instrumentation needs to record measurements, while the destination for those measurements can change according to deployment requirements. A library may need counters for events and histograms for durations, but it should not force every application that uses that library to adopt one particular monitoring service. The README positions `metrics` as a lightweight facade, similar to `log`, and describes it as protocol agnostic.

The target users are split into two groups. Library authors add instrumentation to their code and expose measurements through the facade. Application authors instrument their own services and select exporters to move recorded metrics to an analysis or monitoring system. This division is useful because a library can emit useful measurements while the consuming application remains responsible for deployment-specific export configuration.

The documented scenarios include counting how often a code path is reached, timing code execution, and exposing internal counters or values in a standardized form. Those cases are narrower than a complete observability platform. The repository supplies the instrumentation layer and related components, not a storage database, dashboard, alerting service, or query language. An adopter still needs other software if operational decisions depend on long-term retention, aggregation, visualization, or alerts.

How the metrics Facade Routes Measurements

The repository layout shows a central `metrics` crate alongside specialized crates rather than one executable application. `metrics-util` contains helper types and functions for the ecosystem. `metrics-exporter-prometheus` serves a Prometheus scrape endpoint, while `metrics-exporter-tcp` serves metrics over TCP. `metrics-tracing-context` captures `tracing` span fields as metric labels.

The architecture therefore separates metric definitions from transport and presentation. Application or library code records measurements through the facade. A selected exporter handles the later step of making those measurements available for collection or analysis. The README does not document a single mandatory exporter, configuration file, network address, or runtime initialization sequence, so those details should be taken from the individual crate documentation rather than inferred from the workspace.

The `metrics` crate is described as lightweight and similar in purpose to `log`. That comparison concerns the API boundary, not the underlying data. `metrics` deals with measurements such as counters and timing values, while `metrics-tracing-context` provides a bridge to labels sourced from tracing spans. The repository also lists community integrations for StatsD, New Relic, Sentry, Actix Web, Reqwest, and other components. This supports the central idea that recording code can remain separate from a particular destination.

Protocol agnosticism has a practical consequence. The same recorded measurements can fit more than one collection path, but that does not mean every exporter supports the same transport, lifecycle, or labeling model. The workspace provides separate crates because those concerns are not identical. Application authors must select the boundary that matches their collector instead of expecting the facade to choose one automatically.

The Workspace and Rust Compatibility Boundary

The root `Cargo.toml` defines a Rust workspace with members for `metrics`, `metrics-observer`, `metrics-util`, `metrics-exporter-prometheus`, `metrics-exporter-tcp`, `metrics-exporter-dogstatsd`, and `metrics-tracing-context`. It also includes `metrics-benchmark` and tooling. The workspace uses Rust edition 2021 and declares `rust-version = "1.71.1"`.

The README states that the minimum supported Rust version is currently 1.71.1 and that CI enforces it. It also states a policy of supporting at least the latest four stable Rust minor versions, while generally avoiding dependency upgrades that do not address security or correctness needs. This creates a clear compatibility target for library consumers, but it also means that choosing `metrics` involves checking the facade, exporter, and any related crates together.

The repository has no GitHub releases. Consumers therefore cannot infer a release cadence or migration path from GitHub release entries. The last push was on 2026-09-27. That date confirms recent repository activity, but it does not replace checking crate versions through Cargo or documentation. No specific dependency version is given in the README, so this article does not prescribe a package version that may be absent from that source.

Installing metrics and Choosing a First Use

The README does not provide an installation command or a complete first-use code example. It points readers to the crate documentation on docs.rs and identifies the repository's crates. The first setup step is therefore to inspect the documentation for the specific role: use `metrics` when recording application or library measurements, then inspect an exporter crate when delivery is required.

For a library author, the dependency would need to be added to the library package, followed by calls through the documented instrumentation API. The README does not give the dependency declaration, Cargo feature names, macro names, label types, or setup function signatures. Writing those details here would risk producing code that differs from the current crate interface. The source to use for a first executable example is the `metrics` crate documentation linked from the README.

For an application author, the next decision is which exporter to use. A Prometheus-oriented setup can use `metrics-exporter-prometheus`, which the README says serves a Prometheus scrape endpoint. A TCP-oriented setup can use `metrics-exporter-tcp`, which serves metrics over TCP. The README does not state the port, command-line arguments, builder methods, or runtime hooks for either exporter, so it does not support a complete code or command block here.

A first deployment check should follow the selected exporter. For Prometheus, verify that the documented scrape endpoint exposes measurements emitted by the application. For TCP, verify that the exporter can serve metrics to the intended collector. These are protocol checks, not assertions about unspecified configuration defaults.

Limitations of a Facade-Centered Metrics Design

The main limitation is scope. `metrics` records and organizes measurements, but the README does not claim that it visualizes data, stores historical values, alerts operators, or answers analytical queries. An application that needs those capabilities must connect an exporter to an appropriate backend and decide how that backend is operated.

Instrumentation also has to be written. The facade can make recording consistent and can allow libraries to expose measurements, but it cannot infer which code paths matter in every application. Counting events and timing execution are useful primitives, yet their names, labels, units, and aggregation expectations must fit the surrounding system. The README does not specify a universal naming policy or a complete label schema, so the facade alone cannot guarantee consistent telemetry across unrelated codebases.

Another boundary is the distinction between repository crates and community integrations. The README calls the StatsD, New Relic, Sentry, Actix Web, Reqwest, dashboard, and opinionated interface integrations community-maintained. That distinction affects evaluation because their maintenance and compatibility are not described as part of the core repository's guarantees. This is not a reason to reject them, but it is a reason to review each crate independently.

The absence of GitHub releases also narrows the upgrade story documented by this repository. The MSRV policy and Cargo manifests provide compatibility information, but the README does not provide a migration guide for facade versions or exporter changes. Teams adopting the facade for a public library should treat dependency resolution and the individual crate documentation as part of that compatibility review.

Comparing the Facade with Direct Exporter Integration

A direct alternative is to depend on an exporter and call its recording or serving API from application code. That approach can produce a smaller dependency surface when an application has one fixed monitoring destination and does not need reusable libraries to emit compatible measurements. Its cost is tighter coupling between business or library code and that selected exporter.

`metrics` takes a different boundary. Its central facade is intended to keep recording code at the library or application layer while exporters handle delivery. The README compares the facade to `log`, which supports reading it as a shared instrumentation interface rather than a backend. This is especially relevant to library authors, since applications can collect measurements from instrumented dependencies through the same ecosystem.

A narrower alternative is to rely on `tracing` and `metrics-tracing-context` for contextual labels. The tracing-context crate captures fields from tracing spans as metric labels, but it addresses label propagation rather than the complete metric lifecycle. It does not, by itself, replace the choice of a metric facade or exporter. The appropriate comparison is therefore between a broad instrumentation API, direct backend coupling, and a focused tracing bridge.

MIT Licensing and Workspace Upgrade Scope

The repository is licensed under MIT, and the root workspace configuration repeats that license for its packages. This gives adopters a defined licensing basis under the terms stated in the repository's `LICENSE` and `COPYRIGHT` files. It does not remove the need to inspect dependency licenses when an application adds an exporter or other third-party crate.

The repository is not archived, and the last push was on 2026-09-27. The README describes an MSRV policy intended to preserve compatibility with at least the latest four stable Rust minor versions and to limit dependency churn. That policy can reduce unnecessary upgrade work, but it does not guarantee that every dependency or exporter remains unchanged.

The workspace contains multiple crates, so upgrading the facade may involve evaluating more than one package. Cargo dependency resolution and `Cargo.lock` remain relevant, particularly for applications. The README does not document a formal release process because the repository has no GitHub releases, nor does it provide an exporter migration checklist. The concrete compatibility contract documented here is Rust 1.71.1 as the workspace MSRV, subject to the comment that `metrics-observer` has a higher MSRV.

Editorial conclusion

Adopt metrics-rs/metrics when a Rust library needs a backend-neutral instrumentation API, or when an application team wants to choose its own export path. Do not adopt it alone if you require a complete dashboard, storage system, or alert workflow, because this repository supplies the facade and selected exporters rather than an analysis backend. Verify first that the chosen exporter matches your required protocol and transport, and that your compiler version satisfies the documented MSRV of 1.71.1.

Frequently asked questions

What is metrics-rs/metrics used for in Rust?

It is a lightweight, protocol-agnostic metrics facade for Rust libraries and applications. The README describes counters, timing measurements, and standardized internal values as common use cases.

Does metrics-rs/metrics include exporters?

The repository includes crates for serving Prometheus scrape endpoints and TCP metrics, along with utility and tracing-context crates. It also lists community-maintained integrations such as StatsD, New Relic, and Sentry.

What is the minimum supported Rust version for metrics-rs/metrics?

The README states that the minimum supported Rust version is 1.71.1 and says that CI enforces it. The root `Cargo.toml` also declares `rust-version = "1.71.1"`.

Official sources

  1. Issues
  2. License: MIT
  3. metrics-rs/metrics on GitHub
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/metrics-rs-metrics.svg)](https://hysenlabs.com/projects/metrics-rs-metrics)

Was this useful?