1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-04-13 11:30:31 +02:00

Use slices.SortFunc in OTLP trace exporter instead of sort.Slice (#4989)

Co-authored-by: Sam Xie <sam@samxie.me>
This commit is contained in:
Tyler Yahn 2024-02-28 23:08:43 -08:00 committed by GitHub
parent 32f3933456
commit 0510d11b8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 9 deletions

View File

@ -7,7 +7,8 @@
package otlptracetest // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlptracetest"
import (
"sort"
"cmp"
"slices"
collectortracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
@ -88,8 +89,8 @@ func resourceString(res *resourcepb.Resource) string {
}
func sortedAttributes(attrs []*commonpb.KeyValue) []*commonpb.KeyValue {
sort.Slice(attrs[:], func(i, j int) bool {
return attrs[i].Key < attrs[j].Key
slices.SortFunc(attrs, func(a, b *commonpb.KeyValue) int {
return cmp.Compare(a.Key, b.Key)
})
return attrs
}

View File

@ -7,7 +7,8 @@
package otlptracetest // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlptracetest"
import (
"sort"
"cmp"
"slices"
collectortracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
@ -88,8 +89,8 @@ func resourceString(res *resourcepb.Resource) string {
}
func sortedAttributes(attrs []*commonpb.KeyValue) []*commonpb.KeyValue {
sort.Slice(attrs[:], func(i, j int) bool {
return attrs[i].Key < attrs[j].Key
slices.SortFunc(attrs, func(a, b *commonpb.KeyValue) int {
return cmp.Compare(a.Key, b.Key)
})
return attrs
}

View File

@ -7,7 +7,8 @@
package otlptracetest
import (
"sort"
"cmp"
"slices"
collectortracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
@ -88,8 +89,8 @@ func resourceString(res *resourcepb.Resource) string {
}
func sortedAttributes(attrs []*commonpb.KeyValue) []*commonpb.KeyValue {
sort.Slice(attrs[:], func(i, j int) bool {
return attrs[i].Key < attrs[j].Key
slices.SortFunc(attrs, func(a, b *commonpb.KeyValue) int {
return cmp.Compare(a.Key, b.Key)
})
return attrs
}