1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

attribute: change INVALID Type to EMPTY and mark INVALID as deprecated (#8038)

Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7932

Noticeable comment from previous PR:
https://github.com/open-telemetry/opentelemetry-go/pull/7942#discussion_r2913179215

Print the empty value as empty string per
https://opentelemetry.io/docs/specs/otel/common/#empty-values
This commit is contained in:
Robert Pająk
2026-03-12 09:43:04 +01:00
committed by GitHub
parent 205e24407e
commit f4da59e651
28 changed files with 136 additions and 119 deletions
@@ -26,8 +26,8 @@ var (
attrFloat64Slice = attribute.Float64Slice("float64 slice", []float64{-1, 1})
attrString = attribute.String("string", "o")
attrStringSlice = attribute.StringSlice("string slice", []string{"o", "n"})
attrInvalid = attribute.KeyValue{
Key: attribute.Key("invalid"),
attrEmpty = attribute.KeyValue{
Key: attribute.Key("empty"),
Value: attribute.Value{},
}
@@ -70,12 +70,7 @@ var (
kvFloat64Slice = &cpb.KeyValue{Key: "float64 slice", Value: valDblSlice}
kvString = &cpb.KeyValue{Key: "string", Value: valStrO}
kvStringSlice = &cpb.KeyValue{Key: "string slice", Value: valStrSlice}
kvInvalid = &cpb.KeyValue{
Key: "invalid",
Value: &cpb.AnyValue{
Value: &cpb.AnyValue_StringValue{StringValue: "INVALID"},
},
}
kvEmpty = &cpb.KeyValue{Key: "empty", Value: &cpb.AnyValue{}}
)
func TestAttrTransforms(t *testing.T) {
@@ -89,9 +84,9 @@ func TestAttrTransforms(t *testing.T) {
{"nil", nil, nil},
{"empty", []attribute.KeyValue{}, nil},
{
"invalid",
[]attribute.KeyValue{attrInvalid},
[]*cpb.KeyValue{kvInvalid},
"empty value",
[]attribute.KeyValue{attrEmpty},
[]*cpb.KeyValue{kvEmpty},
},
{
"bool",
@@ -156,7 +151,7 @@ func TestAttrTransforms(t *testing.T) {
attrFloat64Slice,
attrString,
attrStringSlice,
attrInvalid,
attrEmpty,
},
[]*cpb.KeyValue{
kvBool,
@@ -169,7 +164,7 @@ func TestAttrTransforms(t *testing.T) {
kvFloat64Slice,
kvString,
kvStringSlice,
kvInvalid,
kvEmpty,
},
},
} {
@@ -201,6 +201,7 @@ func AttrValue(v attribute.Value) *cpb.AnyValue {
Values: stringSliceValues(v.AsStringSlice()),
},
}
case attribute.EMPTY:
default:
av.Value = &cpb.AnyValue_StringValue{
StringValue: "INVALID",
@@ -327,6 +328,7 @@ func LogAttrValue(v api.Value) *cpb.AnyValue {
Values: LogAttrs(v.AsMap()),
},
}
case api.KindEmpty:
default:
av.Value = &cpb.AnyValue_StringValue{
StringValue: "INVALID",
@@ -24,7 +24,7 @@ var (
logAttrBytes = log.Bytes("bytes", []byte("test"))
logAttrSlice = log.Slice("slice", log.BoolValue(true))
logAttrMap = log.Map("map", logAttrString)
logAttrEmpty = log.Empty("")
logAttrEmpty = log.Empty("empty")
kvBytes = &cpb.KeyValue{
Key: "bytes",
@@ -54,11 +54,6 @@ var (
},
},
}
kvEmpty = &cpb.KeyValue{
Value: &cpb.AnyValue{
Value: &cpb.AnyValue_StringValue{StringValue: "INVALID"},
},
}
)
func TestLogAttrs(t *testing.T) {
@@ -87,6 +87,7 @@ func Value(v attribute.Value) *cpb.AnyValue {
Values: stringSliceValues(v.AsStringSlice()),
},
}
case attribute.EMPTY:
default:
av.Value = &cpb.AnyValue_StringValue{
StringValue: "INVALID",
@@ -26,8 +26,8 @@ var (
attrFloat64Slice = attribute.Float64Slice("float64 slice", []float64{-1, 1})
attrString = attribute.String("string", "o")
attrStringSlice = attribute.StringSlice("string slice", []string{"o", "n"})
attrInvalid = attribute.KeyValue{
Key: attribute.Key("invalid"),
attrEmpty = attribute.KeyValue{
Key: attribute.Key("empty"),
Value: attribute.Value{},
}
@@ -70,12 +70,7 @@ var (
kvFloat64Slice = &cpb.KeyValue{Key: "float64 slice", Value: valDblSlice}
kvString = &cpb.KeyValue{Key: "string", Value: valStrO}
kvStringSlice = &cpb.KeyValue{Key: "string slice", Value: valStrSlice}
kvInvalid = &cpb.KeyValue{
Key: "invalid",
Value: &cpb.AnyValue{
Value: &cpb.AnyValue_StringValue{StringValue: "INVALID"},
},
}
kvEmpty = &cpb.KeyValue{Key: "empty", Value: &cpb.AnyValue{}}
)
type attributeTest struct {
@@ -89,9 +84,9 @@ func TestAttributeTransforms(t *testing.T) {
{"nil", nil, nil},
{"empty", []attribute.KeyValue{}, nil},
{
"invalid",
[]attribute.KeyValue{attrInvalid},
[]*cpb.KeyValue{kvInvalid},
"empty",
[]attribute.KeyValue{attrEmpty},
[]*cpb.KeyValue{kvEmpty},
},
{
"bool",
@@ -156,7 +151,7 @@ func TestAttributeTransforms(t *testing.T) {
attrFloat64Slice,
attrString,
attrStringSlice,
attrInvalid,
attrEmpty,
},
[]*cpb.KeyValue{
kvBool,
@@ -169,7 +164,7 @@ func TestAttributeTransforms(t *testing.T) {
kvFloat64Slice,
kvString,
kvStringSlice,
kvInvalid,
kvEmpty,
},
},
} {