mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-26 03:52:03 +02:00
add _total suffixes to prometheus counters (#3360)
This commit is contained in:
parent
715631d35f
commit
1d9d4b2124
@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- The `"go.opentelemetry.io/otel/exporters/prometheus".New` now also returns an error indicating the failure to register the exporter with Prometheus. (#3239)
|
||||
- The prometheus exporter will no longer try to enumerate the metrics it will send to prometheus on startup.
|
||||
This fixes the `reader is not registered` warning currently emitted on startup. (#3291 #3342)
|
||||
- The `go.opentelemetry.io/otel/exporters/prometheus` exporter now correctly adds _total suffixes to counter metrics. (#3360)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -54,6 +54,10 @@ type collector struct {
|
||||
createTargetInfoOnce sync.Once
|
||||
}
|
||||
|
||||
// prometheus counters MUST have a _total suffix:
|
||||
// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.14.0/specification/metrics/data-model.md#sums-1
|
||||
const counterSuffix = "_total"
|
||||
|
||||
// New returns a Prometheus Exporter.
|
||||
func New(opts ...Option) (*Exporter, error) {
|
||||
cfg := newConfig(opts...)
|
||||
@ -197,8 +201,12 @@ func getSumMetricData[N int64 | float64](sum metricdata.Sum[N], m metricdata.Met
|
||||
}
|
||||
dataPoints := make([]*metricData, 0, len(sum.DataPoints))
|
||||
for _, dp := range sum.DataPoints {
|
||||
name := sanitizeName(m.Name)
|
||||
if sum.IsMonotonic {
|
||||
name += counterSuffix
|
||||
}
|
||||
keys, values := getAttrs(dp.Attributes)
|
||||
desc := prometheus.NewDesc(sanitizeName(m.Name), m.Description, keys, nil)
|
||||
desc := prometheus.NewDesc(name, m.Description, keys, nil)
|
||||
md := &metricData{
|
||||
name: m.Name,
|
||||
description: desc,
|
||||
|
6
exporters/prometheus/testdata/counter.txt
vendored
6
exporters/prometheus/testdata/counter.txt
vendored
@ -1,6 +1,6 @@
|
||||
# HELP foo a simple counter
|
||||
# TYPE foo counter
|
||||
foo{A="B",C="D",E="true",F="42"} 24.3
|
||||
# HELP foo_total a simple counter
|
||||
# TYPE foo_total counter
|
||||
foo_total{A="B",C="D",E="true",F="42"} 24.3
|
||||
# HELP target_info Target metadata
|
||||
# TYPE target_info gauge
|
||||
target_info{service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
# HELP foo a simple counter
|
||||
# TYPE foo counter
|
||||
foo{A="B",C="D",E="true",F="42"} 24.3
|
||||
# HELP foo_total a simple counter
|
||||
# TYPE foo_total counter
|
||||
foo_total{A="B",C="D",E="true",F="42"} 24.3
|
||||
# HELP target_info Target metadata
|
||||
# TYPE target_info gauge
|
||||
target_info{A="B",C="D",service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
# HELP foo a simple counter
|
||||
# TYPE foo counter
|
||||
foo{A="B",C="D",E="true",F="42"} 24.3
|
||||
# HELP foo_total a simple counter
|
||||
# TYPE foo_total counter
|
||||
foo_total{A="B",C="D",E="true",F="42"} 24.3
|
||||
# HELP target_info Target metadata
|
||||
# TYPE target_info gauge
|
||||
target_info 1
|
||||
|
@ -1,6 +1,7 @@
|
||||
# HELP foo a sanitary counter
|
||||
# TYPE foo counter
|
||||
foo{A_B="Q",C_D="Y;Z"} 24.3
|
||||
# HELP foo_total a sanitary counter
|
||||
# TYPE foo_total counter
|
||||
foo_total{A_B="Q",C_D="Y;Z"} 24.3
|
||||
# HELP target_info Target metadata
|
||||
# TYPE target_info gauge
|
||||
target_info{service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
# HELP bar a fun little gauge
|
||||
# TYPE bar gauge
|
||||
bar{A="B",C="D"} 75
|
||||
# HELP _0invalid_counter_name a counter with an invalid name
|
||||
# TYPE _0invalid_counter_name counter
|
||||
_0invalid_counter_name{A="B",C="D"} 100
|
||||
# HELP _0invalid_counter_name_total a counter with an invalid name
|
||||
# TYPE _0invalid_counter_name_total counter
|
||||
_0invalid_counter_name_total{A="B",C="D"} 100
|
||||
# HELP invalid_gauge_name a gauge with an invalid name
|
||||
# TYPE invalid_gauge_name gauge
|
||||
invalid_gauge_name{A="B",C="D"} 100
|
||||
|
@ -1,3 +1,3 @@
|
||||
# HELP foo a simple counter
|
||||
# TYPE foo counter
|
||||
foo{A="B",C="D",E="true",F="42"} 24.3
|
||||
# HELP foo_total a simple counter
|
||||
# TYPE foo_total counter
|
||||
foo_total{A="B",C="D",E="true",F="42"} 24.3
|
||||
|
Loading…
x
Reference in New Issue
Block a user