diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf3420f59d..dc2602e568e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Use OpenCensus `metric` package for process metrics instead of `stats` package (#5486) - Update OTLP to v0.18.0 (#5530) +- Log histogram min/max fields with `logging` exporter (#5520) ### 🧰 Bug fixes 🧰 diff --git a/internal/otlptext/databuffer.go b/internal/otlptext/databuffer.go index 2e7e4a28d5d..0316071d617 100644 --- a/internal/otlptext/databuffer.go +++ b/internal/otlptext/databuffer.go @@ -117,7 +117,18 @@ func (b *dataBuffer) logDoubleHistogramDataPoints(ps pmetric.HistogramDataPointS b.logEntry("StartTimestamp: %s", p.StartTimestamp()) b.logEntry("Timestamp: %s", p.Timestamp()) b.logEntry("Count: %d", p.Count()) - b.logEntry("Sum: %f", p.Sum()) + + if p.HasSum() { + b.logEntry("Sum: %f", p.Sum()) + } + + if p.HasMin() { + b.logEntry("Min: %f", p.Min()) + } + + if p.HasMax() { + b.logEntry("Max: %f", p.Max()) + } bounds := p.MExplicitBounds() if len(bounds) != 0 { @@ -144,7 +155,18 @@ func (b *dataBuffer) logExponentialHistogramDataPoints(ps pmetric.ExponentialHis b.logEntry("StartTimestamp: %s", p.StartTimestamp()) b.logEntry("Timestamp: %s", p.Timestamp()) b.logEntry("Count: %d", p.Count()) - b.logEntry("Sum: %f", p.Sum()) + + if p.HasSum() { + b.logEntry("Sum: %f", p.Sum()) + } + + if p.HasMin() { + b.logEntry("Min: %f", p.Min()) + } + + if p.HasMax() { + b.logEntry("Max: %f", p.Max()) + } scale := int(p.Scale()) factor := math.Ldexp(math.Ln2, -scale) diff --git a/internal/testdata/metric.go b/internal/testdata/metric.go index 02737d5b625..977f64f753d 100644 --- a/internal/testdata/metric.go +++ b/internal/testdata/metric.go @@ -206,6 +206,8 @@ func initHistogramMetric(hm pmetric.Metric) { hdp1.SetTimestamp(TestMetricTimestamp) hdp1.SetCount(1) hdp1.SetSum(15) + hdp1.SetMin(15) + hdp1.SetMax(15) hdp1.SetMBucketCounts([]uint64{0, 1}) exemplar := hdp1.Exemplars().AppendEmpty() exemplar.SetTimestamp(TestMetricExemplarTimestamp) @@ -247,6 +249,8 @@ func initExponentialHistogramMetric(hm pmetric.Metric) { hdp1.SetTimestamp(TestMetricTimestamp) hdp1.SetCount(3) hdp1.SetSum(1.25) + hdp1.SetMin(0) + hdp1.SetMax(1) hdp1.SetZeroCount(1) hdp1.SetScale(-1)