MCPcopy
hub / github.com/grafana/tempo / MarshalToJSONV1

Function MarshalToJSONV1

pkg/tempopb/trace_utils.go:14–22  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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`.
14func 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.

Callers 2

HTTPFinalMethod · 0.92
TestMarshalToJSONV1Function · 0.85

Calls

no outgoing calls

Tested by 1

TestMarshalToJSONV1Function · 0.68