You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-19 21:45:50 +02:00
exporters: support MAP attributes (#8453)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/8163 Add end-to-end exporter handling for `attribute.SLICE` in the remaining paths that still treated it as invalid or relied on fallback formatting. Changes: - encode `attribute.MAP` as OTLP `AnyValue_AnyValue_KvlistValue` for trace, log, and metric transforms - serialize Zipkin `MAP` attributes using the non-OTLP AnyValue string representation
This commit is contained in:
@@ -182,10 +182,10 @@ func attributeToStringPair(kv attribute.KeyValue) (string, string) {
|
||||
}
|
||||
encoded, _ := json.Marshal(data)
|
||||
return string(kv.Key), string(encoded)
|
||||
case attribute.SLICE:
|
||||
case attribute.SLICE, attribute.MAP:
|
||||
// Note that this is a best effort support as this exporter is already deprecated.
|
||||
// Yet, we want to preserve other existing behavior as much as possible.
|
||||
// Emit the slice using the non-OTLP AnyValue string representation.
|
||||
// Emit the value using the non-OTLP AnyValue string representation.
|
||||
// Some values will be emitted differently than the specific types above.
|
||||
return string(kv.Key), kv.Value.String()
|
||||
default:
|
||||
|
||||
@@ -1003,6 +1003,29 @@ func TestAttributeToStringPairSlice(t *testing.T) {
|
||||
assert.Equal(t, `[true,"Ymlu",[2,null]]`, v)
|
||||
}
|
||||
|
||||
func TestAttributeToStringPairMap(t *testing.T) {
|
||||
k, v := attributeToStringPair(attribute.Map(
|
||||
"map",
|
||||
attribute.String("string", "o"),
|
||||
attribute.Int("number", 2),
|
||||
attribute.ByteSlice("bytes", []byte("bin")),
|
||||
attribute.Slice(
|
||||
"slice",
|
||||
attribute.BoolValue(true),
|
||||
attribute.MapValue(attribute.String("inner", "value")),
|
||||
),
|
||||
attribute.Map("nested", attribute.Bool("ok", true)),
|
||||
attribute.KeyValue{Key: "empty"},
|
||||
))
|
||||
|
||||
assert.Equal(t, "map", k)
|
||||
assert.JSONEq(
|
||||
t,
|
||||
`{"bytes":"Ymlu","empty":null,"nested":{"ok":true},"number":2,"slice":[true,{"inner":"value"}],"string":"o"}`,
|
||||
v,
|
||||
)
|
||||
}
|
||||
|
||||
func zkmodelIDPtr(n uint64) *zkmodel.ID {
|
||||
id := zkmodel.ID(n)
|
||||
return &id
|
||||
|
||||
Reference in New Issue
Block a user