Skip to content

Commit

Permalink
add exemplar support to the OTLP HTTP and gRPC exporters (#4900)
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Feb 12, 2024
1 parent dd5d054 commit ec03021
Show file tree
Hide file tree
Showing 7 changed files with 737 additions and 69 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,8 @@ The next release will require at least [Go 1.21].
### Added

- Support [Go 1.22]. (#4890)
- Add exemplar support to `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#4900)
- Add exemplar support to `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4900)

## [1.23.1] 2024-02-07

Expand Down
Expand Up @@ -148,6 +148,7 @@ func DataPoints[N int64 | float64](dPts []metricdata.DataPoint[N]) []*mpb.Number
Attributes: AttrIter(dPt.Attributes.Iter()),
StartTimeUnixNano: timeUnixNano(dPt.StartTime),
TimeUnixNano: timeUnixNano(dPt.Time),
Exemplars: Exemplars(dPt.Exemplars),
}
switch v := any(dPt.Value).(type) {
case int64:
Expand Down Expand Up @@ -193,6 +194,7 @@ func HistogramDataPoints[N int64 | float64](dPts []metricdata.HistogramDataPoint
Sum: &sum,
BucketCounts: dPt.BucketCounts,
ExplicitBounds: dPt.Bounds,
Exemplars: Exemplars(dPt.Exemplars),
}
if v, ok := dPt.Min.Value(); ok {
vF64 := float64(v)
Expand Down Expand Up @@ -236,6 +238,7 @@ func ExponentialHistogramDataPoints[N int64 | float64](dPts []metricdata.Exponen
Sum: &sum,
Scale: dPt.Scale,
ZeroCount: dPt.ZeroCount,
Exemplars: Exemplars(dPt.Exemplars),

Positive: ExponentialHistogramDataPointBuckets(dPt.PositiveBucket),
Negative: ExponentialHistogramDataPointBuckets(dPt.NegativeBucket),
Expand Down Expand Up @@ -290,3 +293,28 @@ func timeUnixNano(t time.Time) uint64 {
}
return uint64(t.UnixNano())
}

// Exemplars returns a slice of OTLP Exemplars generated from exemplars.
func Exemplars[N int64 | float64](exemplars []metricdata.Exemplar[N]) []*mpb.Exemplar {
out := make([]*mpb.Exemplar, 0, len(exemplars))
for _, exemplar := range exemplars {
e := &mpb.Exemplar{
FilteredAttributes: KeyValues(exemplar.FilteredAttributes),
TimeUnixNano: timeUnixNano(exemplar.Time),
SpanId: exemplar.SpanID,
TraceId: exemplar.TraceID,
}
switch v := any(exemplar.Value).(type) {
case int64:
e.Value = &mpb.Exemplar_AsInt{
AsInt: v,
}
case float64:
e.Value = &mpb.Exemplar_AsDouble{
AsDouble: v,
}
}
out = append(out, e)
}
return out
}

0 comments on commit ec03021

Please sign in to comment.