Skip to content

Commit

Permalink
[exporter/logging] log min and max for histograms (#5520)
Browse files Browse the repository at this point in the history
* fix(exporter/logging): log min and max for histograms.

* fix(changelog): update changelog.

* fix(otlptext): check if sum/min/max are present before adding them to the buffer.

* fix(otlptext): make test data include a variation of histogram min/max presence.

* fix(otlptext): check if sum exists on exponential histogram before adding it to the buffer.

* fix(otlptext): use min=0 for ExponentialHistogram test data as zero_count=1.
  • Loading branch information
pichlermarc authored Jun 14, 2022
1 parent a7792d3 commit e5ac6d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🧰

Expand Down
26 changes: 24 additions & 2 deletions internal/otlptext/databuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/testdata/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e5ac6d2

Please sign in to comment.