Tempo: show hex strings instead of uints for ids (#36471)

joshhunt/test-azure-sdk-react
Zoltán Bedi 4 years ago committed by GitHub
parent c02ead9113
commit ee89e51c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      pkg/tsdb/tempo/trace_transform.go
  2. 2
      pkg/tsdb/tempo/trace_transform_test.go

@ -3,6 +3,7 @@ package tempo
import (
"encoding/json"
"fmt"
"strings"
"github.com/grafana/grafana-plugin-sdk-go/data"
"go.opentelemetry.io/collector/consumer/pdata"
@ -101,18 +102,12 @@ func resourceSpansToRows(rs pdata.ResourceSpans) ([][]interface{}, error) {
}
func spanToSpanRow(span pdata.Span, libraryTags pdata.InstrumentationLibrary, resource pdata.Resource) ([]interface{}, error) {
traceID, err := traceIDToString(span.TraceID())
if err != nil {
return nil, err
}
traceID := span.TraceID().HexString()
traceID = strings.TrimLeft(traceID, "0")
spanID, err := spanIDToString(span.SpanID())
if err != nil {
return nil, err
}
spanID := span.SpanID().HexString()
// Should get error only if empty in which case we are ok with empty string
parentSpanID, _ := spanIDToString(span.ParentSpanID())
parentSpanID := span.ParentSpanID().HexString()
startTime := float64(span.StartTimestamp()) / 1_000_000
serviceName, serviceTags := resourceToProcess(resource)
@ -153,23 +148,6 @@ func toJSONString(json []byte) string {
return s
}
// TraceID can be the size of 2 uint64 in OT but we just need a string
func traceIDToString(traceID pdata.TraceID) (string, error) {
traceIDHigh, traceIDLow := tracetranslator.TraceIDToUInt64Pair(traceID)
if traceIDLow == 0 && traceIDHigh == 0 {
return "", fmt.Errorf("OC span has an all zeros trace ID")
}
return fmt.Sprintf("%d%d", traceIDHigh, traceIDLow), nil
}
func spanIDToString(spanID pdata.SpanID) (string, error) {
uSpanID := tracetranslator.SpanIDToUInt64(spanID)
if uSpanID == 0 {
return "", fmt.Errorf("OC span has an all zeros span ID")
}
return fmt.Sprintf("%d", uSpanID), nil
}
func resourceToProcess(resource pdata.Resource) (string, []*KeyValue) {
attrs := resource.Attributes()
serviceName := tracetranslator.ResourceNoServiceName

@ -40,7 +40,7 @@ func TestTraceToFrame(t *testing.T) {
require.Equal(t, "", root["logs"])
require.Equal(t, "[{\"value\":\"const\",\"key\":\"sampler.type\"},{\"value\":true,\"key\":\"sampler.param\"},{\"value\":200,\"key\":\"http.status_code\"},{\"value\":\"GET\",\"key\":\"http.method\"},{\"value\":\"/loki/api/v1/query_range?direction=BACKWARD\\u0026limit=1000\\u0026query=%7Bcompose_project%3D%22devenv%22%7D%20%7C%3D%22traceID%22\\u0026start=1616070921000000000\\u0026end=1616072722000000000\\u0026step=2\",\"key\":\"http.url\"},{\"value\":\"net/http\",\"key\":\"component\"},{\"value\":\"server\",\"key\":\"span.kind\"},{\"value\":0,\"key\":\"status.code\"}]", root["tags"])
span := bFrame.FindRowWithValue("spanID", "8185345640360084998")
span := bFrame.FindRowWithValue("spanID", "7198307df9748606")
require.Equal(t, "GetParallelChunks", span["operationName"])
require.Equal(t, "loki-all", span["serviceName"])

Loading…
Cancel
Save