You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
Drop support for Go 1.20 (#4967)
* Update README.md * Remove 1.20 support from CI workflows * Update all go mod * Add changelog entry * Update go mod tidy target * Run go mod tidy * Replace sliceEqualFunc with slices.EqualFunc * Replace grow with slices.Grow * Replace ensureAttributesCapacity with slices.Grow * Replace conditional with min * Use slices module for slice comparison in metricdatatest
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
module go.opentelemetry.io/otel/log
|
||||
|
||||
go 1.20
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/go-logr/logr v1.4.1
|
||||
|
||||
@@ -6,6 +6,7 @@ github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
|
||||
+3
-28
@@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"math"
|
||||
"slices"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
@@ -261,11 +262,9 @@ func (v Value) Equal(w Value) bool {
|
||||
case KindFloat64:
|
||||
return v.asFloat64() == w.asFloat64()
|
||||
case KindSlice:
|
||||
// TODO: replace with slices.EqualFunc when Go 1.20 support dropped.
|
||||
return sliceEqualFunc(v.asSlice(), w.asSlice(), Value.Equal)
|
||||
return slices.EqualFunc(v.asSlice(), w.asSlice(), Value.Equal)
|
||||
case KindMap:
|
||||
// TODO: replace with slices.EqualFunc when Go 1.20 support dropped.
|
||||
return sliceEqualFunc(v.asMap(), w.asMap(), KeyValue.Equal)
|
||||
return slices.EqualFunc(v.asMap(), w.asMap(), KeyValue.Equal)
|
||||
case KindBytes:
|
||||
return bytes.Equal(v.asBytes(), w.asBytes())
|
||||
case KindEmpty:
|
||||
@@ -276,30 +275,6 @@ func (v Value) Equal(w Value) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// sliceEqualFunc reports whether two slices are equal using an equality
|
||||
// function on each pair of elements. If the lengths are different,
|
||||
// sliceEqualFunc returns false. Otherwise, the elements are compared in
|
||||
// increasing index order, and the comparison stops at the first index for
|
||||
// which eq returns false.
|
||||
//
|
||||
// This is based on [EqualFunc]. It was added to provide backwards
|
||||
// compatibility for Go 1.20. When Go 1.20 is no longer supported it can be
|
||||
// removed.
|
||||
//
|
||||
// EqualFunc: https://pkg.go.dev/slices#EqualFunc
|
||||
func sliceEqualFunc[T any](s1 []T, s2 []T, eq func(T, T) bool) bool {
|
||||
if len(s1) != len(s2) {
|
||||
return false
|
||||
}
|
||||
for i, v1 := range s1 {
|
||||
v2 := s2[i]
|
||||
if !eq(v1, v2) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// An KeyValue is a key-value pair used to represent a log attribute (a
|
||||
// superset of [go.opentelemetry.io/otel/attribute.KeyValue]) and map item.
|
||||
type KeyValue struct {
|
||||
|
||||
+5
-18
@@ -14,7 +14,10 @@
|
||||
|
||||
package log // import "go.opentelemetry.io/otel/log"
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
// attributesInlineCount is the number of attributes that are efficiently
|
||||
// stored in an array within a Record. This value is borrowed from slog which
|
||||
@@ -125,26 +128,10 @@ func (r *Record) AddAttributes(attrs ...KeyValue) {
|
||||
r.nFront++
|
||||
}
|
||||
|
||||
// TODO: when Go 1.20 is no longer supported, use slices.Grow instead.
|
||||
r.back = grow(r.back, len(attrs[i:]))
|
||||
r.back = slices.Grow(r.back, len(attrs[i:]))
|
||||
r.back = append(r.back, attrs[i:]...)
|
||||
}
|
||||
|
||||
// grow increases the slice's capacity, if necessary, to guarantee space for
|
||||
// another n elements. After grow(n), at least n elements can be appended to
|
||||
// the slice without another allocation.
|
||||
//
|
||||
// This is based on [Grow]. It is not available in Go 1.20 so it is reproduced
|
||||
// here.
|
||||
//
|
||||
// [Grow]: https://pkg.go.dev/slices#Grow
|
||||
func grow(slice []KeyValue, n int) []KeyValue {
|
||||
if n -= cap(slice) - len(slice); n > 0 {
|
||||
slice = append(slice[:cap(slice)], make([]KeyValue, n)...)[:len(slice)]
|
||||
}
|
||||
return slice
|
||||
}
|
||||
|
||||
// AttributesLen returns the number of attributes in the log record.
|
||||
func (r *Record) AttributesLen() int {
|
||||
return r.nFront + len(r.back)
|
||||
|
||||
Reference in New Issue
Block a user