|
|
|
|
@ -1,12 +1,12 @@ |
|
|
|
|
package tempo |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"encoding/hex" |
|
|
|
|
"encoding/json" |
|
|
|
|
"fmt" |
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data" |
|
|
|
|
"go.opentelemetry.io/collector/model/pdata" |
|
|
|
|
"go.opentelemetry.io/collector/pdata/pcommon" |
|
|
|
|
"go.opentelemetry.io/collector/pdata/ptrace" |
|
|
|
|
"go.opentelemetry.io/otel/attribute" |
|
|
|
|
@ -118,12 +118,16 @@ func resourceSpansToRows(rs ptrace.ResourceSpans) ([][]interface{}, error) { |
|
|
|
|
|
|
|
|
|
func spanToSpanRow(span ptrace.Span, libraryTags pcommon.InstrumentationScope, resource pcommon.Resource) ([]interface{}, error) { |
|
|
|
|
// If the id representation changed from hexstring to something else we need to change the transformBase64IDToHexString in the frontend code
|
|
|
|
|
traceID := span.TraceID().HexString() |
|
|
|
|
traceID = strings.TrimPrefix(traceID, strings.Repeat("0", 16)) |
|
|
|
|
traceID := span.TraceID() |
|
|
|
|
traceIDHex := hex.EncodeToString(traceID[:]) |
|
|
|
|
traceIDHex = strings.TrimPrefix(traceIDHex, strings.Repeat("0", 16)) |
|
|
|
|
|
|
|
|
|
spanID := span.SpanID().HexString() |
|
|
|
|
spanID := span.SpanID() |
|
|
|
|
spanIDHex := hex.EncodeToString(spanID[:]) |
|
|
|
|
|
|
|
|
|
parentSpanID := span.ParentSpanID() |
|
|
|
|
parentSpanIDHex := hex.EncodeToString(parentSpanID[:]) |
|
|
|
|
|
|
|
|
|
parentSpanID := span.ParentSpanID().HexString() |
|
|
|
|
startTime := float64(span.StartTimestamp()) / 1_000_000 |
|
|
|
|
serviceName, serviceTags := resourceToProcess(resource) |
|
|
|
|
|
|
|
|
|
@ -158,9 +162,9 @@ func spanToSpanRow(span ptrace.Span, libraryTags pcommon.InstrumentationScope, r |
|
|
|
|
|
|
|
|
|
// Order matters (look at dataframe order)
|
|
|
|
|
return []interface{}{ |
|
|
|
|
traceID, |
|
|
|
|
spanID, |
|
|
|
|
parentSpanID, |
|
|
|
|
traceIDHex, |
|
|
|
|
spanIDHex, |
|
|
|
|
parentSpanIDHex, |
|
|
|
|
span.Name(), |
|
|
|
|
serviceName, |
|
|
|
|
getSpanKind(span.Kind()), |
|
|
|
|
@ -188,7 +192,7 @@ func resourceToProcess(resource pcommon.Resource) (string, []*KeyValue) { |
|
|
|
|
tags := make([]*KeyValue, 0, attrs.Len()-1) |
|
|
|
|
attrs.Range(func(key string, attr pcommon.Value) bool { |
|
|
|
|
if attribute.Key(key) == semconv.ServiceNameKey { |
|
|
|
|
serviceName = attr.StringVal() |
|
|
|
|
serviceName = attr.Str() |
|
|
|
|
} |
|
|
|
|
tags = append(tags, &KeyValue{Key: key, Value: getAttributeVal(attr)}) |
|
|
|
|
return true |
|
|
|
|
@ -199,14 +203,14 @@ func resourceToProcess(resource pcommon.Resource) (string, []*KeyValue) { |
|
|
|
|
|
|
|
|
|
func getAttributeVal(attr pcommon.Value) interface{} { |
|
|
|
|
switch attr.Type() { |
|
|
|
|
case pcommon.ValueTypeString: |
|
|
|
|
return attr.StringVal() |
|
|
|
|
case pcommon.ValueTypeStr: |
|
|
|
|
return attr.Str() |
|
|
|
|
case pcommon.ValueTypeInt: |
|
|
|
|
return attr.IntVal() |
|
|
|
|
return attr.Int() |
|
|
|
|
case pcommon.ValueTypeBool: |
|
|
|
|
return attr.BoolVal() |
|
|
|
|
return attr.Bool() |
|
|
|
|
case pcommon.ValueTypeDouble: |
|
|
|
|
return attr.DoubleVal() |
|
|
|
|
return attr.Double() |
|
|
|
|
case pcommon.ValueTypeMap, pcommon.ValueTypeSlice: |
|
|
|
|
return attr.AsString() |
|
|
|
|
default: |
|
|
|
|
@ -243,8 +247,8 @@ func getSpanKind(spanKind ptrace.SpanKind) string { |
|
|
|
|
return tagStr |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getTraceState(traceState ptrace.TraceState) string { |
|
|
|
|
return string(traceState) |
|
|
|
|
func getTraceState(traceState pcommon.TraceState) string { |
|
|
|
|
return traceState.AsRaw() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func spanEventsToLogs(events ptrace.SpanEventSlice) []*TraceLog { |
|
|
|
|
@ -275,7 +279,7 @@ func spanEventsToLogs(events ptrace.SpanEventSlice) []*TraceLog { |
|
|
|
|
return logs |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func spanLinksToReferences(links pdata.SpanLinkSlice) []*TraceReference { |
|
|
|
|
func spanLinksToReferences(links ptrace.SpanLinkSlice) []*TraceReference { |
|
|
|
|
if links.Len() == 0 { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
@ -284,10 +288,12 @@ func spanLinksToReferences(links pdata.SpanLinkSlice) []*TraceReference { |
|
|
|
|
for i := 0; i < links.Len(); i++ { |
|
|
|
|
link := links.At(i) |
|
|
|
|
|
|
|
|
|
traceId := link.TraceID().HexString() |
|
|
|
|
traceId = strings.TrimLeft(traceId, "0") |
|
|
|
|
traceID := link.TraceID() |
|
|
|
|
traceIDHex := hex.EncodeToString(traceID[:]) |
|
|
|
|
traceIDHex = strings.TrimLeft(traceIDHex, "0") |
|
|
|
|
|
|
|
|
|
spanId := link.SpanID().HexString() |
|
|
|
|
spanID := link.SpanID() |
|
|
|
|
spanIDHex := hex.EncodeToString(spanID[:]) |
|
|
|
|
|
|
|
|
|
tags := make([]*KeyValue, 0, link.Attributes().Len()) |
|
|
|
|
link.Attributes().Range(func(key string, attr pcommon.Value) bool { |
|
|
|
|
@ -296,8 +302,8 @@ func spanLinksToReferences(links pdata.SpanLinkSlice) []*TraceReference { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
references = append(references, &TraceReference{ |
|
|
|
|
TraceID: traceId, |
|
|
|
|
SpanID: spanId, |
|
|
|
|
TraceID: traceIDHex, |
|
|
|
|
SpanID: spanIDHex, |
|
|
|
|
Tags: tags, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|