Tempo: remove deprecated model package usage (remove replace) (#71687)

* Tempo: remove deprecated model package usage (remove replace)

* fix root test
This commit is contained in:
Charandas
2023-07-18 09:30:29 -07:00
committed by GitHub
parent 4a59022fe8
commit 614f1af190
6 changed files with 55 additions and 43 deletions

View File

@ -5,13 +5,13 @@ as soon as we can use agent as a dependency this can be refactored
package frontendlogging
import (
"encoding/hex"
"fmt"
"sort"
"strings"
"time"
om "github.com/wk8/go-ordered-map"
"go.opentelemetry.io/collector/model/otlp"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
)
@ -148,7 +148,7 @@ type Traces struct {
// UnmarshalJSON unmarshals Traces model.
func (t *Traces) UnmarshalJSON(b []byte) error {
unmarshaler := otlp.NewJSONTracesUnmarshaler()
unmarshaler := ptrace.JSONUnmarshaler{}
td, err := unmarshaler.UnmarshalTraces(b)
if err != nil {
return err
@ -159,7 +159,7 @@ func (t *Traces) UnmarshalJSON(b []byte) error {
// MarshalJSON marshals Traces model to json.
func (t Traces) MarshalJSON() ([]byte, error) {
marshaler := otlp.NewJSONTracesMarshaler()
marshaler := ptrace.JSONMarshaler{}
return marshaler.MarshalTraces(t.Traces)
}
@ -182,6 +182,15 @@ func (t Traces) SpanSlice() []ptrace.Span {
// SpanToKeyVal returns KeyVal representation of a Span.
func SpanToKeyVal(s ptrace.Span) *KeyVal {
traceID := s.TraceID()
traceIDHex := hex.EncodeToString(traceID[:])
spanID := s.SpanID()
spanIDHex := hex.EncodeToString(spanID[:])
parentSpanID := s.ParentSpanID()
parentSpanIDHex := hex.EncodeToString(parentSpanID[:])
kv := NewKeyVal()
if s.StartTimestamp() > 0 {
KeyValAdd(kv, "timestamp", s.StartTimestamp().AsTime().String())
@ -190,11 +199,11 @@ func SpanToKeyVal(s ptrace.Span) *KeyVal {
KeyValAdd(kv, "end_timestamp", s.StartTimestamp().AsTime().String())
}
KeyValAdd(kv, "kind", "span")
KeyValAdd(kv, "traceID", s.TraceID().HexString())
KeyValAdd(kv, "spanID", s.SpanID().HexString())
KeyValAdd(kv, "traceID", traceIDHex)
KeyValAdd(kv, "spanID", spanIDHex)
KeyValAdd(kv, "span_kind", s.Kind().String())
KeyValAdd(kv, "name", s.Name())
KeyValAdd(kv, "parent_spanID", s.ParentSpanID().HexString())
KeyValAdd(kv, "parent_spanID", parentSpanIDHex)
s.Attributes().Range(func(k string, v pcommon.Value) bool {
KeyValAdd(kv, "attr_"+k, fmt.Sprintf("%v", v))
return true