Tempo: Fix unexpected trimming of leading zeroes in traceID (#55167)

* tempo: fix unexpected trim traceID leading zero (#55166)

* fix lint
This commit is contained in:
Jimmie Han 2022-09-28 21:49:12 +08:00 committed by GitHub
parent ef641ea9c9
commit c6dffb11a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -111,7 +111,7 @@ func resourceSpansToRows(rs pdata.ResourceSpans) ([][]interface{}, error) {
func spanToSpanRow(span pdata.Span, libraryTags pdata.InstrumentationLibrary, resource pdata.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.TrimLeft(traceID, "0")
traceID = strings.TrimPrefix(traceID, strings.Repeat("0", 16))
spanID := span.SpanID().HexString()

View File

@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/stretchr/testify/require"
otlp "go.opentelemetry.io/collector/model/otlp"
"go.opentelemetry.io/collector/model/pdata"
)
func TestTraceToFrame(t *testing.T) {
@ -51,6 +52,43 @@ func TestTraceToFrame(t *testing.T) {
require.Equal(t, json.RawMessage("[{\"timestamp\":1616072924072.856,\"fields\":[{\"value\":1,\"key\":\"chunks requested\"}]},{\"timestamp\":1616072924072.9448,\"fields\":[{\"value\":1,\"key\":\"chunks fetched\"}]}]"), span["logs"])
require.Equal(t, json.RawMessage("[{\"value\":0,\"key\":\"status.code\"}]"), span["tags"])
})
t.Run("should transform correct traceID", func(t *testing.T) {
proto, err := os.ReadFile("testData/tempo_proto_response")
require.NoError(t, err)
otTrace, err := otlp.NewProtobufTracesUnmarshaler().UnmarshalTraces(proto)
require.NoError(t, err)
var index int
otTrace.ResourceSpans().RemoveIf(func(rsp pdata.ResourceSpans) bool {
rsp.InstrumentationLibrarySpans().RemoveIf(func(sp pdata.InstrumentationLibrarySpans) bool {
sp.Spans().RemoveIf(func(span pdata.Span) bool {
if index == 0 {
span.SetTraceID(pdata.NewTraceID([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}))
}
if index == 1 {
span.SetTraceID(pdata.NewTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7}))
}
index++
return false
})
return false
})
return false
})
frame, err := TraceToFrame(otTrace)
require.NoError(t, err)
bFrame := &BetterFrame{frame}
traceID128Bit := bFrame.GetRow(0)
require.NotNil(t, traceID128Bit)
require.Equal(t, "00010203040506070001020304050607", traceID128Bit["traceID"])
traceID64Bit := bFrame.GetRow(1)
require.NotNil(t, traceID64Bit)
require.Equal(t, "0001020304050607", traceID64Bit["traceID"])
})
}
type Row map[string]interface{}