exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms.#777
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #777 +/- ##
==========================================
- Coverage 60.73% 59.79% -0.95%
==========================================
Files 56 56
Lines 5649 5743 +94
==========================================
+ Hits 3431 3434 +3
- Misses 2070 2159 +89
- Partials 148 150 +2 ☔ View full report in Codecov by Sentry. |
|
The feature has been implemented in the OTel SDK: https://github.com/open-telemetry/opentelemetry-go/blob/main/sdk/metric/internal/x/README.md#exemplars Let me know if you are interested in contributing this. |
f1d62de to
df2fd53
Compare
df2fd53 to
aa41056
Compare
| func toDistributionExemplar[N int64 | float64](Exemplars []metricdata.Exemplar[N]) []*distribution.Distribution_Exemplar { | ||
| var exemplars []*distribution.Distribution_Exemplar | ||
| for _, e := range Exemplars { | ||
| exemplars = append(exemplars, &distribution.Distribution_Exemplar{Value: float64(e.Value), Timestamp: timestamppb.New(e.Time)}) |
There was a problem hiding this comment.
Verified Distribution_Exemplar only supports float64 values : https://pkg.go.dev/google.golang.org/genproto/googleapis/api/distribution#Distribution_Exemplar
| positiveBucketCounts := 0 | ||
| growthFactor := math.Exp2(math.Exp2(-float64(hist.Scale))) | ||
| for i, v := range hist.PositiveBucket.Counts { | ||
| counts[i] = int64(v) |
There was a problem hiding this comment.
Opentelemetry Exponential Buckets support Negative Indices too, but AFAIU the TypedValue Exponential Buckets only support Positive Indices.
There was a problem hiding this comment.
Thats correct. All negative observations and zero observations should be in the underflow bucket. See
opentelemetry-operations-go/exporter/collector/metrics.go
Lines 989 to 993 in 87124ac
There was a problem hiding this comment.
Fixed. I used as reference the implementation of collector/metrics.go : exponentialHistogramPoint to reimplement all the mentioned details of expHistToDistribution in this review, but using the correct types and methods.
| google.golang.org/protobuf v1.31.0 // indirect | ||
| ) | ||
|
|
||
| replace github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric => ../../../exporter/metric |
There was a problem hiding this comment.
Added this to pick current changes (before merging) to metric.go.
| positiveBucketCounts := 0 | ||
| growthFactor := math.Exp2(math.Exp2(-float64(hist.Scale))) | ||
| for i, v := range hist.PositiveBucket.Counts { | ||
| counts[i] = int64(v) |
There was a problem hiding this comment.
Thats correct. All negative observations and zero observations should be in the underflow bucket. See
opentelemetry-operations-go/exporter/collector/metrics.go
Lines 989 to 993 in 87124ac
…t` as reference for `expHistToDistribution`.
|
@dashpole Update on last changes to PR :
|
Co-authored-by: David Ashpole <dashpole@google.com> Signed-off-by: Francisco Valente Castro <1435136+franciscovalentecastro@users.noreply.github.com>
|
Follow-up tasks required:
@franciscovalentecastro can you add the README? You are welcome to work on the other tasks as well if you have time. Otherwise, I'll make sure they get done. Just let me know which you'd like to tackle |
This PR adds the following functionality to the
exporter/metric:ExponentialHistogram.TypedValueDistribution (eitherHistogramandExponentialHistogram) with exemplars.exponential_histogramexample with adashboard.jsonto visualize it.Details :
Exemplarto metricdata package open-telemetry/opentelemetry-go#3849 added theExemplardata type and theExemplarsfield to aHistogramDataPoint.Exemplarsampling support.