Observability and metrics for Rust applications
| Tier | operations |
| Role | unclassified (baselined) |
| Path | crates/operations/metrics |
| Edition | 2021 |
| Targets | operations_metrics |
| Public items | 54 across 0 modules |
| Tests | 23 |
What it is for
Observability and metrics library crates for Rust applications.
This crate provides abstractions for collecting and exporting application metrics (counters, gauges, histograms).
Capabilities
Counter
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub struct Counter |
Counter :: fn new(name : impl Into <String>, help : impl Into <String>) -> Self |
Counter :: fn with_labels(mut self, labels : Labels) -> Self |
Counter :: fn inc(& self) |
Counter :: fn inc_by(& self, v : u64) |
Counter :: fn get(& self) -> u64 |
Counter :: fn reset(& self) |
Counter :: fn name(& self) -> & str |
Counter :: fn help(& self) -> & str |
Gauge
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub struct Gauge |
Gauge :: fn new(name : impl Into <String>, help : impl Into <String>) -> Self |
Gauge :: fn with_labels(mut self, labels : Labels) -> Self |
Gauge :: fn set(& self, v : i64) |
Gauge :: fn inc(& self) |
Gauge :: fn dec(& self) |
Gauge :: fn add(& self, v : i64) |
Gauge :: fn sub(& self, v : i64) |
Gauge :: fn get(& self) -> i64 |
Gauge :: fn name(& self) -> & str |
Histogram
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub struct Histogram |
Histogram :: fn new(name : impl Into <String>, help : impl Into <String>) -> Self |
Histogram :: fn with_buckets(name : impl Into <String>, help : impl Into <String>, mut buckets : Vec <f64>,) -> Self |
Histogram :: fn with_labels(mut self, labels : Labels) -> Self |
Histogram :: fn observe(& self, v : f64) |
Histogram :: fn get_count(& self) -> u64 |
Histogram :: fn get_sum(& self) -> f64 |
Histogram :: fn get_buckets(& self) -> Vec <HistogramBucket> |
Histogram :: fn name(& self) -> & str |
HistogramBucket
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub struct HistogramBucket |
Labels
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub type Labels: HashMap <String, String> |
MetricSample
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub struct MetricSample |
MetricSample :: fn new(name : impl Into <String>, metric_type : MetricType, value : f64) -> Self |
MetricSample :: fn with_label(mut self, key : impl Into <String>, value : impl Into <String>) -> Self |
MetricType
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub enum MetricType |
MetricType :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
MetricsError
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub enum MetricsError |
Registry:Registry
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub struct Registry |
Registry:counter
Observability and metrics library crates for Rust applications.
| Item |
|---|
Registry :: fn counter(& self, name : impl Into <String>, help : impl Into <String>) -> Arc <Counter> |
Registry:export
Observability and metrics library crates for Rust applications.
| Item |
|---|
Registry :: fn export_prometheus(& self) -> String |
Registry :: fn export_json(& self) -> serde_json::Value |
Registry:gauge
Observability and metrics library crates for Rust applications.
| Item |
|---|
Registry :: fn gauge(& self, name : impl Into <String>, help : impl Into <String>) -> Arc <Gauge> |
Registry:get
Observability and metrics library crates for Rust applications.
| Item |
|---|
Registry :: fn get_counter(& self, name : & str) -> Option <Arc <Counter>> |
Registry :: fn get_gauge(& self, name : & str) -> Option <Arc <Gauge>> |
Registry :: fn get_histogram(& self, name : & str) -> Option <Arc <Histogram>> |
Registry:histogram
Observability and metrics library crates for Rust applications.
| Item |
|---|
Registry :: fn histogram(& self, name : impl Into <String>, help : impl Into <String>) -> Arc <Histogram> |
Registry:new
Observability and metrics library crates for Rust applications.
| Item |
|---|
Registry :: fn new() -> Self |
Registry:register
Observability and metrics library crates for Rust applications.
| Item |
|---|
Registry :: fn register_counter(& self, counter : Counter) -> Arc <Counter> |
Registry :: fn register_gauge(& self, gauge : Gauge) -> Arc <Gauge> |
Registry :: fn register_histogram(& self, histogram : Histogram) -> Arc <Histogram> |
Result
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub type Result<T>: std::result::Result <T, MetricsError> |
Timer
Observability and metrics library crates for Rust applications.
| Item |
|---|
pub struct Timer |
Timer :: fn new(histogram : Arc <Histogram>) -> Self |
Timer :: fn stop(self) -> f64 |
Timer :: fn drop(& mut self) |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum MetricsError | Errors that can occur with metrics. |
pub type Result<T>: std::result::Result <T, MetricsError> | Result type for metrics operations. |
pub enum MetricType | Metric type. |
MetricType :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub type Labels: HashMap <String, String> | Labels for a metric (key-value pairs). |
pub struct Counter | A metric counter. |
Counter :: fn new(name : impl Into <String>, help : impl Into <String>) -> Self | Creates a new counter. |
Counter :: fn with_labels(mut self, labels : Labels) -> Self | Creates a counter with labels. |
Counter :: fn inc(& self) | Increments the counter by 1. |
Counter :: fn inc_by(& self, v : u64) | Increments the counter by a value. |
Counter :: fn get(& self) -> u64 | Gets the current value. |
Counter :: fn reset(& self) | Resets the counter. |
Counter :: fn name(& self) -> & str | Gets the metric name. |
Counter :: fn help(& self) -> & str | Gets the help text. |
pub struct Gauge | A metric gauge. |
Gauge :: fn new(name : impl Into <String>, help : impl Into <String>) -> Self | Creates a new gauge. |
Gauge :: fn with_labels(mut self, labels : Labels) -> Self | Creates a gauge with labels. |
Gauge :: fn set(& self, v : i64) | Sets the gauge value. |
Gauge :: fn inc(& self) | Increments the gauge by 1. |
Gauge :: fn dec(& self) | Decrements the gauge by 1. |
Gauge :: fn add(& self, v : i64) | Adds to the gauge. |
Gauge :: fn sub(& self, v : i64) | Subtracts from the gauge. |
Gauge :: fn get(& self) -> i64 | Gets the current value. |
Gauge :: fn name(& self) -> & str | Gets the metric name. |
pub struct HistogramBucket | Histogram bucket. |
pub struct Histogram | A metric histogram. |
Histogram :: fn new(name : impl Into <String>, help : impl Into <String>) -> Self | Creates a new histogram with default buckets. |
Histogram :: fn with_buckets(name : impl Into <String>, help : impl Into <String>, mut buckets : Vec <f64>,) -> Self | Creates a histogram with custom buckets. |
Histogram :: fn with_labels(mut self, labels : Labels) -> Self | Creates a histogram with labels. |
Histogram :: fn observe(& self, v : f64) | Observes a value. |
Histogram :: fn get_count(& self) -> u64 | Gets the observation count. |
Histogram :: fn get_sum(& self) -> f64 | Gets the sum of observations. |
Histogram :: fn get_buckets(& self) -> Vec <HistogramBucket> | Gets bucket data. |
Histogram :: fn name(& self) -> & str | Gets the metric name. |
pub struct Timer | Timer for measuring duration. |
Timer :: fn new(histogram : Arc <Histogram>) -> Self | Creates a new timer. |
Timer :: fn stop(self) -> f64 | Stops the timer and records the duration. |
Timer :: fn drop(& mut self) | — |
pub struct Registry | Metrics registry. |
Registry :: fn new() -> Self | Creates a new registry. |
Registry :: fn register_counter(& self, counter : Counter) -> Arc <Counter> | Registers a counter. |
Registry :: fn register_gauge(& self, gauge : Gauge) -> Arc <Gauge> | Registers a gauge. |
Registry :: fn register_histogram(& self, histogram : Histogram) -> Arc <Histogram> | Registers a histogram. |
Registry :: fn get_counter(& self, name : & str) -> Option <Arc <Counter>> | Gets a counter by name. |
Registry :: fn get_gauge(& self, name : & str) -> Option <Arc <Gauge>> | Gets a gauge by name. |
Registry :: fn get_histogram(& self, name : & str) -> Option <Arc <Histogram>> | Gets a histogram by name. |
Registry :: fn counter(& self, name : impl Into <String>, help : impl Into <String>) -> Arc <Counter> | Gets or creates a counter. |
Registry :: fn gauge(& self, name : impl Into <String>, help : impl Into <String>) -> Arc <Gauge> | Gets or creates a gauge. |
Registry :: fn histogram(& self, name : impl Into <String>, help : impl Into <String>) -> Arc <Histogram> | Gets or creates a histogram. |
Registry :: fn export_prometheus(& self) -> String | Exports metrics in Prometheus format. |
Registry :: fn export_json(& self) -> serde_json::Value | Exports metrics as JSON. |
pub struct MetricSample | Metric sample for export. |
MetricSample :: fn new(name : impl Into <String>, metric_type : MetricType, value : f64) -> Self | Creates a new sample. |
MetricSample :: fn with_label(mut self, key : impl Into <String>, value : impl Into <String>) -> Self | Adds a label. |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier operations with 40 other crates: operations-approval-workflow, operations-assessments, operations-block-imaging, operations-boot-media, operations-browser-agent-worker, operations-camera-discovery, operations-camera-liveview, operations-camera-registry, … (40 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | operations |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/operations/metrics |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
thiserror | ^2 | — | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1 | full | no | always |
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_metrics["application-metrics"] -->|uses| SELF SELF["operations-metrics"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | operations_metrics | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
MetricsError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: application-metrics.
Verification
| Kind | Count |
|---|---|
| Unit tests | 23 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 11 | 0 | 1 |
What the tests establish, by name:
test_counter_inc—src/lib.rstest_counter_inc_by—src/lib.rstest_counter_new—src/lib.rstest_counter_reset—src/lib.rstest_counter_with_labels—src/lib.rstest_error_display—src/lib.rstest_gauge_add_sub—src/lib.rstest_gauge_inc_dec—src/lib.rstest_gauge_new—src/lib.rstest_gauge_set—src/lib.rstest_histogram_bucket_serialization—src/lib.rstest_histogram_buckets—src/lib.rstest_histogram_new—src/lib.rstest_histogram_observe—src/lib.rstest_metric_sample_new—src/lib.rstest_metric_type_display—src/lib.rstest_registry_counter—src/lib.rstest_registry_export_json—src/lib.rstest_registry_export_prometheus—src/lib.rstest_registry_gauge—src/lib.rstest_registry_histogram—src/lib.rstest_registry_new—src/lib.rstest_timer—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 52 | 54 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 52
"No rustdoc detected" : 2
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 755 |
| Code lines | 572 |
| Public API items | 54 |
| Public modules | 0 |
| Tests | 23 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 4 |
| Workspace reverse dependencies | 1 |
pie showData
title Public API by kind
"enum" : 2
"method" : 43
"struct" : 7
"type alias" : 2
pie showData
title Rust source composition
"Code" : 572
"Blank or comment" : 183
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.