You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-08-10 22:31:50 +02:00
Fix slice-valued attributes when used as map keys (#2223)
* Fix slice-valued attributes when used as map keys Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com> * store pointers to slice values to make them usable as map keys Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com> * Emit slice-typed attribute values as slices, not pointers to slices Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
df2bdbbadb
commit
eaacfaa801
@@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Slice-valued attributes can correctly be used as map keys. (#2223)
|
||||
|
||||
## [1.0.0-RC3] - 2021-09-02
|
||||
|
||||
### Added
|
||||
|
@@ -77,7 +77,7 @@ func BoolSliceValue(v []bool) Value {
|
||||
copy(cp, v)
|
||||
return Value{
|
||||
vtype: BOOLSLICE,
|
||||
slice: cp,
|
||||
slice: &cp,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func IntSliceValue(v []int) Value {
|
||||
}
|
||||
return Value{
|
||||
vtype: INT64SLICE,
|
||||
slice: cp,
|
||||
slice: &cp,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ func Int64SliceValue(v []int64) Value {
|
||||
copy(cp, v)
|
||||
return Value{
|
||||
vtype: INT64SLICE,
|
||||
slice: cp,
|
||||
slice: &cp,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func Float64SliceValue(v []float64) Value {
|
||||
copy(cp, v)
|
||||
return Value{
|
||||
vtype: FLOAT64SLICE,
|
||||
slice: cp,
|
||||
slice: &cp,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func StringSliceValue(v []string) Value {
|
||||
copy(cp, v)
|
||||
return Value{
|
||||
vtype: STRINGSLICE,
|
||||
slice: cp,
|
||||
slice: &cp,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,8 +197,8 @@ func (v Value) AsBool() bool {
|
||||
// AsBoolSlice returns the []bool value. Make sure that the Value's type is
|
||||
// BOOLSLICE.
|
||||
func (v Value) AsBoolSlice() []bool {
|
||||
if s, ok := v.slice.([]bool); ok {
|
||||
return s
|
||||
if s, ok := v.slice.(*[]bool); ok {
|
||||
return *s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -212,8 +212,8 @@ func (v Value) AsInt64() int64 {
|
||||
// AsInt64Slice returns the []int64 value. Make sure that the Value's type is
|
||||
// INT64SLICE.
|
||||
func (v Value) AsInt64Slice() []int64 {
|
||||
if s, ok := v.slice.([]int64); ok {
|
||||
return s
|
||||
if s, ok := v.slice.(*[]int64); ok {
|
||||
return *s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -227,8 +227,8 @@ func (v Value) AsFloat64() float64 {
|
||||
// AsFloat64Slice returns the []float64 value. Make sure that the Value's type is
|
||||
// INT64SLICE.
|
||||
func (v Value) AsFloat64Slice() []float64 {
|
||||
if s, ok := v.slice.([]float64); ok {
|
||||
return s
|
||||
if s, ok := v.slice.(*[]float64); ok {
|
||||
return *s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -242,8 +242,8 @@ func (v Value) AsString() string {
|
||||
// AsStringSlice returns the []string value. Make sure that the Value's type is
|
||||
// INT64SLICE.
|
||||
func (v Value) AsStringSlice() []string {
|
||||
if s, ok := v.slice.([]string); ok {
|
||||
return s
|
||||
if s, ok := v.slice.(*[]string); ok {
|
||||
return *s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -285,14 +285,22 @@ func (v Value) AsInterface() interface{} {
|
||||
// Emit returns a string representation of Value's data.
|
||||
func (v Value) Emit() string {
|
||||
switch v.Type() {
|
||||
case ARRAY, BOOLSLICE, INT64SLICE, FLOAT64SLICE, STRINGSLICE:
|
||||
case ARRAY:
|
||||
return fmt.Sprint(v.slice)
|
||||
case BOOLSLICE:
|
||||
return fmt.Sprint(*(v.slice.(*[]bool)))
|
||||
case BOOL:
|
||||
return strconv.FormatBool(v.AsBool())
|
||||
case INT64SLICE:
|
||||
return fmt.Sprint(*(v.slice.(*[]int64)))
|
||||
case INT64:
|
||||
return strconv.FormatInt(v.AsInt64(), 10)
|
||||
case FLOAT64SLICE:
|
||||
return fmt.Sprint(*(v.slice.(*[]float64)))
|
||||
case FLOAT64:
|
||||
return fmt.Sprint(v.AsFloat64())
|
||||
case STRINGSLICE:
|
||||
return fmt.Sprint(*(v.slice.(*[]string)))
|
||||
case STRING:
|
||||
return v.stringly
|
||||
default:
|
||||
|
@@ -266,7 +266,7 @@ func TestSpanData(t *testing.T) {
|
||||
DroppedAttributes: 1,
|
||||
DroppedEvents: 2,
|
||||
DroppedLinks: 3,
|
||||
Resource: resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5)),
|
||||
Resource: resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5), attribute.StringSlice("rk3", []string{"sv1", "sv2"})),
|
||||
InstrumentationLibrary: instrumentation.Library{
|
||||
Name: "go.opentelemetry.io/test/otel",
|
||||
Version: "v0.0.1",
|
||||
|
Reference in New Issue
Block a user