Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prometheus counters should have _total suffix #952

Merged
merged 4 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion opentelemetry-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ mod sanitize;

use sanitize::sanitize;

/// Monotonic Sum metric points MUST have _total added as a suffix to the metric name
/// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.14.0/specification/metrics/data-model.md#sums-1
const MONOTONIC_COUNTER_SUFFIX: &str = "_total";

/// Create a new prometheus exporter builder.
pub fn exporter(controller: BasicController) -> ExporterBuilder {
ExporterBuilder::new(controller)
Expand Down Expand Up @@ -330,7 +334,7 @@ fn build_monotonic_counter(
m.set_counter(c);

let mut mf = prometheus::proto::MetricFamily::default();
mf.set_name(desc.name);
mf.set_name(desc.name + MONOTONIC_COUNTER_SUFFIX);
mf.set_help(desc.help);
mf.set_field_type(prometheus::proto::MetricType::COUNTER);
mf.set_metric(protobuf::RepeatedField::from_vec(vec![m]));
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-prometheus/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn free_unused_instruments() {
counter.add(&cx, 10.0, &attributes);
counter.add(&cx, 5.3, &attributes);

expected.push(r#"counter{A="B",C="D",R="V"} 15.3"#);
expected.push(r#"counter_total{A="B",C="D",R="V"} 15.3"#);
}
// Standard export
compare_export(&exporter, expected.clone());
Expand Down Expand Up @@ -73,7 +73,7 @@ fn test_add() {
counter.add(&cx, 10.0, &attributes);
counter.add(&cx, 5.3, &attributes);

expected.push(r#"counter{A="B",C="D",R="V"} 15.3"#);
expected.push(r#"counter_total{A="B",C="D",R="V"} 15.3"#);

let cb_attributes = attributes.clone();
let gauge = meter.i64_observable_gauge("intgauge").init();
Expand Down