Skip to content

Commit c08bb45

Browse files
authored
Documentation fixes (autometrics-dev#11)
* Add description and license to macros crate * Fix typo in dependency * Use unicode emojis * Remove git link from readme * Show prometheus exporter on docs.rs * Add module doc comments * Use github link in docs
1 parent 48fb93b commit c08bb45

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ prometheus-exporter = ["once_cell", "opentelemetry-prometheus", "prometheus"]
1818
autometrics-macros = { version = "0.1.0", path = "./macros" }
1919
const_format = { version = "0.2", features = ["rust_1_51"] }
2020
opentelemetry_api = { version = "0.18", default-features = false, features = ["metrics"] }
21-
opentelemetry_sdk = { verison = "0.18", default-features = false, features = ["metrics"] }
21+
opentelemetry_sdk = { version = "0.18", default-features = false, features = ["metrics"] }
2222

2323
# Used for prometheus-exporter feature
2424
once_cell = { version = "1.17", optional = true }

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Autometrics :chart_with_upwards_trend: :sparkles:
1+
# Autometrics 📈✨
22
> Easily add metrics to your system -- and actually understand them using automatically customized Prometheus queries.
33
44
[![Documentation](https://docs.rs/autometrics/badge.svg)](https://docs.rs/autometrics)
55
[![Crates.io](https://img.shields.io/crates/v/autometrics.svg)](https://crates.io/crates/autometrics)
66
[![Discord Shield](https://discordapp.com/api/guilds/950489382626951178/widget.png?style=shield)](https://discord.gg/kHtwcH8As9)
77

88
Metrics are powerful and relatively inexpensive, but they are still hard to use. Developers need to:
9-
- Think about what metrics to track and which metric type to use (counter, gauge... :confused:)
10-
- Figure out how to write PromQL or another query language to get some data :confounded:
11-
- Verify that the data returned actually answers the right question :tired_face:
9+
- Think about what metrics to track and which metric type to use (counter, gauge... 😕)
10+
- Figure out how to write PromQL or another query language to get some data 😖
11+
- Verify that the data returned actually answers the right question 😫
1212

1313
Autometrics makes it easy to add metrics to any function in your codebase.
14-
Then, automatically generates common Prometheus for each function to help you easily understand the data.
14+
Then, it automatically generates common Prometheus for each function to help you easily understand the data.
1515
Explore your production metrics directly from your editor/IDE.
1616

17-
### :one: Add `#[autometrics]` to your code
17+
### 1️⃣ Add `#[autometrics]` to your code
1818

1919
```rust
2020
#[autometrics]
@@ -23,15 +23,15 @@ async fn create_user(Json(payload): Json<CreateUser>) -> Result<Json<User>, ApiE
2323
}
2424
```
2525

26-
### :two: Hover over the function name to see the generated queries
26+
### 2️⃣ Hover over the function name to see the generated queries
2727

2828
<img src="./assets/vs-code-example.png" alt="VS Code Hover Example" width="500">
2929

30-
### :three: Click a query link to go directly to the Prometheus chart for that function
30+
### 3️⃣ Click a query link to go directly to the Prometheus chart for that function
3131

3232
<img src="./assets/prometheus-chart.png" alt="Prometheus Chart" width="500">
3333

34-
### :four: Go back to shipping features :rocket:
34+
### 4️⃣ Go back to shipping features 🚀
3535

3636
## See it in action
3737

@@ -95,21 +95,21 @@ Autometrics includes optional functions to help collect and prepare metrics to b
9595
In your `Cargo.toml` file, enable the optional `prometheus-exporter` feature:
9696

9797
```toml
98-
autometrics = { git = "ssh://[email protected]/fiberplane/autometrics-rs.git", branch = "main", features = ["prometheus-exporter"] }
98+
autometrics = { version = "*", features = ["prometheus-exporter"] }
9999
```
100100

101101
Then, call the `global_metrics_exporter` function in your `main` function:
102102
```rust
103103
pub fn main() {
104-
let _exporter = global_metrics_exporter();
104+
let _exporter = autometrics::global_metrics_exporter();
105105
// ...
106106
}
107107
```
108108

109109
And create a route on your API (probably mounted under `/metrics`) that returns the following:
110110
```rust
111111
pub fn get_metrics() -> (StatusCode, String) {
112-
match encode_global_metrics() {
112+
match autometrics::encode_global_metrics() {
113113
Ok(metrics) => (StatusCode::OK, metrics),
114114
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, format!("{:?}", err))
115115
}

macros/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
name = "autometrics-macros"
33
version = "0.1.0"
44
edition = "2021"
5+
authors = ["Fiberplane <[email protected]>", "Evan Schwartz <[email protected]>"]
6+
description = "Macros for the autometrics crate"
7+
documentation = "https://docs.rs/autometrics"
8+
readme = "../README.md"
9+
repository = "https://github.com/fiberplane/autometrics-rs"
10+
license = "MIT OR Apache-2.0"
11+
keywords = ["metrics", "prometheus", "opentelemetry"]
12+
categories = ["development-tools::profiling"]
513

614
[lib]
715
proc-macro = true

macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const DEFAULT_PROMETHEUS_URL: &str = "http://localhost:9090";
2121
///
2222
/// For all of the generated metrics, Autometrics attaches the following labels:
2323
/// - `function` - the name of the function
24-
/// - `module` - the module path of the function (with `::` replaced by `_`)
24+
/// - `module` - the module path of the function (with `::` replaced by `.`)
2525
///
2626
/// For the function call counter, Autometrics attaches these additional labels:
2727
/// - `result` - if the function returns a `Result`, this will either be `ok` or `error`

src/lib.rs

+44
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
1+
//! # Autometrics
2+
//!
3+
//! Autometrics is a library that makes it easy to collect metrics for any function
4+
//! -- and easily understand the data with automatically generated Prometheus queries for each function.
5+
//!
6+
//! ## Example
7+
//! See the [example](https://github.com/fiberplane/autometrics-rs/blob/main/examples/axum.rs) for a full example of how to use Autometrics.
8+
//!
9+
//! ## Usage
10+
//! 1. Annotate any function with `#[autometrics]` to collect metrics for that function:
11+
//!
12+
//! ```rust
13+
//! #[autometrics]
14+
//! async fn create_user(Json(payload): Json<CreateUser>) -> Result<Json<User>, ApiError> {
15+
//! // ...
16+
//! }
17+
//! ```
18+
//!
19+
//! 2. Call the `global_metrics_exporter` function in your `main` function:
20+
//! ```rust
21+
//! pub fn main() {
22+
//! let _exporter = autometrics::global_metrics_exporter();
23+
//! // ...
24+
//! }
25+
//! ```
26+
//!
27+
//! 3. Create a route on your API (probably mounted under `/metrics`) for Prometheus to scrape:
28+
//! ```rust
29+
//! pub fn get_metrics() -> (StatusCode, String) {
30+
//! match autometrics::encode_global_metrics() {
31+
//! Ok(metrics) => (StatusCode::OK, metrics),
32+
//! Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, format!("{:?}", err))
33+
//! }
34+
//! }
35+
//! ```
36+
//!
37+
//! 4. Hover over any autometrics-enabled function to see the links to graphs of the generated metrics
38+
//! 5. Click on the link to see the graph of the live metrics for that function
39+
//!
40+
//! ## Feature flags
41+
//!
42+
//! - `prometheus-exporter`: Exports a Prometheus metrics collector and exporter
43+
//!
144
mod labels;
245
#[cfg(feature = "prometheus-exporter")]
346
mod prometheus;
447
mod task_local;
548
mod tracker;
649

750
#[cfg(feature = "prometheus-exporter")]
51+
#[cfg_attr(docsrs, doc(cfg(feature = "prometheus-exporter")))]
852
pub use self::prometheus::*;
953
pub use autometrics_macros::autometrics;
1054

0 commit comments

Comments
 (0)