diff --git a/CHANGELOG.md b/CHANGELOG.md index 34be9d346ae..4656e968b4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Slice attributes of `attribute` package are now comparable based on their value, not instance. (#3108 #3252) - Prometheus exporter will now cumulatively sum histogram buckets. (#3281) - Export the sum of each histogram datapoint uniquely with the `go.opentelemetry.io/otel/exporters/otlpmetric` exporters. (#3284, #3293) +- UpDownCounters are now correctly output as prometheus gauges in the `go.opentelemetry.io/otel/exporters/prometheus` exporter. (#3358) ## [1.11.0/0.32.3] 2022-10-12 diff --git a/exporters/prometheus/exporter.go b/exporters/prometheus/exporter.go index 01c555970cc..d7db199955f 100644 --- a/exporters/prometheus/exporter.go +++ b/exporters/prometheus/exporter.go @@ -168,6 +168,10 @@ func getHistogramMetricData(histogram metricdata.Histogram, m metricdata.Metrics } func getSumMetricData[N int64 | float64](sum metricdata.Sum[N], m metricdata.Metrics) []*metricData { + valueType := prometheus.CounterValue + if !sum.IsMonotonic { + valueType = prometheus.GaugeValue + } dataPoints := make([]*metricData, 0, len(sum.DataPoints)) for _, dp := range sum.DataPoints { keys, values := getAttrs(dp.Attributes) @@ -176,7 +180,7 @@ func getSumMetricData[N int64 | float64](sum metricdata.Sum[N], m metricdata.Met name: m.Name, description: desc, attributeValues: values, - valueType: prometheus.CounterValue, + valueType: valueType, value: float64(dp.Value), } dataPoints = append(dataPoints, md) diff --git a/exporters/prometheus/testdata/gauge.txt b/exporters/prometheus/testdata/gauge.txt index 889295d74e1..d9db4dc0911 100644 --- a/exporters/prometheus/testdata/gauge.txt +++ b/exporters/prometheus/testdata/gauge.txt @@ -1,3 +1,3 @@ # HELP bar a fun little gauge -# TYPE bar counter +# TYPE bar gauge bar{A="B",C="D"} 75 diff --git a/exporters/prometheus/testdata/sanitized_names.txt b/exporters/prometheus/testdata/sanitized_names.txt index 509055705a3..7516a771819 100644 --- a/exporters/prometheus/testdata/sanitized_names.txt +++ b/exporters/prometheus/testdata/sanitized_names.txt @@ -1,11 +1,11 @@ # HELP bar a fun little gauge -# TYPE bar counter +# 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 invalid_gauge_name a gauge with an invalid name -# TYPE invalid_gauge_name counter +# TYPE invalid_gauge_name gauge invalid_gauge_name{A="B",C="D"} 100 # HELP invalid_hist_name a histogram with an invalid name # TYPE invalid_hist_name histogram