opentelemetry-go icon indicating copy to clipboard operation
opentelemetry-go copied to clipboard

SpanID, TraceID, KeyValue and other structs cannot be unmarshalled from JSON

Open toby-allsopp opened this issue 3 years ago • 3 comments

Description

A number of structs, e.g. trace.SpanID, define MarshalJSON methods but not the corresponding UnmarshalJSON. This means that the JSON written by the stdout exporter, which consists of a stream of []*SpanSnapshot values, cannot be unmarshalled back into Go objects easily.

Environment

  • OS: Linux
  • Architecture: amd64
  • Go Version: 1.15.7
  • opentelemetry-go version: v0.19.0

Steps To Reproduce

ss := trace.SpanSnapshot{}
b, _ := json.Marshal(ss)
var ss2 trace.SpanSnapshot
err := json.Unmarshal(b, &ss2)
require.NoError(t, err)
require.Equal(t, ss, ss2)

Expected behavior

It would be helpful if the JSON produced by marshalling a slice of SpanSnapshots was easily unmashalled back into a slice of SpanSnapshots.

toby-allsopp avatar Apr 19 '21 02:04 toby-allsopp