It marshal a Trace to an OTEL compatible JSON. Historically, our Trace proto message used `batches` to define the array of resourses spans. To be OTEL compatible we renamed it to `resourcesSpans`. To be backward compatible, this function use jsonpb to marshal the Trace to an OTEL compatible JSON and
(t *Trace)
| 12 | // To be backward compatible, this function use jsonpb to marshal the Trace to an OTEL compatible JSON |
| 13 | // and then replace the first occurrence of `resourceSpan` by `batches`. |
| 14 | func MarshalToJSONV1(t *Trace) ([]byte, error) { |
| 15 | marshaler := &jsonpb.Marshaler{} |
| 16 | jsonStr, err := marshaler.MarshalToString(t) |
| 17 | if err != nil { |
| 18 | return nil, err |
| 19 | } |
| 20 | jsonStr = strings.Replace(jsonStr, `"resourceSpans":`, `"batches":`, 1) |
| 21 | return []byte(jsonStr), nil |
| 22 | } |
| 23 | |
| 24 | // It unmarshal an OTEL compatible JSON to a Trace. |
| 25 | // Historically, our Trace proto message used `batches` to define the array of resourses spans. |
no outgoing calls