Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exemplar support to the OTLP HTTP and gRPC exporters #4900

Merged
merged 1 commit into from Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}