A Rust crate for exporting OpenTelemetry metrics in the OpenMetrics text format.
This serves as a protobuf-free alternative to the discontinued opentelemetry-prometheus crate.
This implementation tries to follow the OpenTelemetry-to-OpenMetrics conversion spec, though it takes some liberties where it contradicts the OpenMetrics spec. Some edge cases and complex metrics setups may not be handled correctly. See Tracey spec tracking for how spec-compliance is tracked.
- Conversion of
opentelemetry-sdkmetric data to OpenMetrics-compliant text. - Ready-to-use Exporter to register in
opentelemetry, outputs metrics in the OpenMetrics text format.
use std::time::Duration;
use ottotom::exporter::OpenMetricsExporter;
use opentelemetry_sdk::metrics::PeriodicReader;
use opentelemetry_sdk::metrics::SdkMeterProvider;
pub fn init_openmetrics_exporter() -> OpenMetricsExporter {
let exporter = OpenMetricsExporter::default();
let reader = PeriodicReader::builder(exporter.clone())
.with_interval(Duration::from_secs(1))
.build();
let meter_provider = SdkMeterProvider::builder()
.with_reader(reader)
.build();
opentelemetry::global::set_meter_provider(meter_provider);
exporter
}
let exporter = init_openmetrics_exporter();
// Retain the exporter in you app state. Register some opentelmetry meters and fill them with data.
// Later on (e.g. in a `/metrics` endpoint) read the current metrics:
let openmetrics = exporter.text();
println!("{}", openmetrics);This project uses Tracey to track which requirements of its
source specifications are implemented and tested. The configuration lives in
.config/tracey/config.styx and tracks two specification documents:
docs/spec/openmetrics.md, condensed from the OpenMetrics text format spec. Annotations use theom[...]prefix.docs/spec/conversion.md, condensed from the OTLP metric points to Prometheus conversion spec. Annotations use thec[...]prefix.
Spec requirements are referenced inline in the code via comment annotations:
// om[impl text.eof] // this code implements a requirement
// om[verify text.eof] // this test verifies a requirement
// c[related metadata.unit-suffix] // loosely connected
Useful commands:
mise run tracey-statuscoverage overview per spec/implementation.mise run tracey-validatevalidate annotation references and naming.tracey webinteractive coverage dashboard.tracey uncovered/tracey untestedlist the remaining work.