mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
Tempo: Fix [object Object] shown as an Event message in Trace view (#73473)
Remove the wrapper json value
This commit is contained in:
parent
dd21584961
commit
3aae7b089e
@ -263,7 +263,7 @@ func spanEventsToLogs(events ptrace.SpanEventSlice) []*TraceLog {
|
||||
if event.Name() != "" {
|
||||
fields = append(fields, &KeyValue{
|
||||
Key: TagMessage,
|
||||
Value: attribute.StringValue(event.Name()),
|
||||
Value: event.Name(),
|
||||
})
|
||||
}
|
||||
event.Attributes().Range(func(key string, attr pcommon.Value) bool {
|
||||
|
@ -18,7 +18,8 @@ func TestTraceToFrame(t *testing.T) {
|
||||
// like json. You could tediously create the structures manually using all the setters for everything or use
|
||||
// https://github.com/grafana/tempo/tree/master/pkg/tempopb to create the protobuf structs from something like
|
||||
// json. At the moment just saving some real tempo proto response into file and loading was the easiest and
|
||||
// as my patience was diminished trying to figure this out, I say it's good enough.
|
||||
// as my patience was diminished trying to figure this out, I say it's good enough. You can also just modify
|
||||
// the trace afterward as you wish.
|
||||
proto, err := os.ReadFile("testData/tempo_proto_response")
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -26,6 +27,11 @@ func TestTraceToFrame(t *testing.T) {
|
||||
otTrace, err := pbUnmarshaler.UnmarshalTraces(proto)
|
||||
require.NoError(t, err)
|
||||
|
||||
// For some reason the trace does not have named events (probably was generated some time ago) so we just set
|
||||
// one here for testing
|
||||
origSpan := findSpan(otTrace, "7198307df9748606")
|
||||
origSpan.Events().At(0).SetName("test event")
|
||||
|
||||
frame, err := TraceToFrame(otTrace)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -51,7 +57,7 @@ func TestTraceToFrame(t *testing.T) {
|
||||
require.Equal(t, json.RawMessage("[{\"value\":\"loki-all\",\"key\":\"service.name\"},{\"value\":\"Jaeger-Go-2.25.0\",\"key\":\"opencensus.exporterversion\"},{\"value\":\"4d019a031941\",\"key\":\"host.hostname\"},{\"value\":\"172.18.0.6\",\"key\":\"ip\"},{\"value\":\"4b19ace06df8e4de\",\"key\":\"client-uuid\"}]"), span["serviceTags"])
|
||||
require.Equal(t, 1616072924072.852, span["startTime"])
|
||||
require.Equal(t, 0.094, span["duration"])
|
||||
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, "[{\"timestamp\":1616072924072.856,\"fields\":[{\"value\":\"test event\",\"key\":\"message\"},{\"value\":1,\"key\":\"chunks requested\"}]},{\"timestamp\":1616072924072.9448,\"fields\":[{\"value\":1,\"key\":\"chunks fetched\"}]}]", string(span["logs"].(json.RawMessage)))
|
||||
})
|
||||
|
||||
t.Run("should transform correct traceID", func(t *testing.T) {
|
||||
@ -137,6 +143,22 @@ func fieldNames(frame *data.Frame) []string {
|
||||
return names
|
||||
}
|
||||
|
||||
func findSpan(trace ptrace.Traces, spanId string) *ptrace.Span {
|
||||
for i := 0; i < trace.ResourceSpans().Len(); i++ {
|
||||
scope := trace.ResourceSpans().At(i).ScopeSpans()
|
||||
for j := 0; j < scope.Len(); j++ {
|
||||
spans := scope.At(j).Spans()
|
||||
for k := 0; k < spans.Len(); k++ {
|
||||
if spans.At(k).SpanID().String() == spanId {
|
||||
found := spans.At(k)
|
||||
return &found
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var fields = []string{
|
||||
"traceID",
|
||||
"spanID",
|
||||
|
Loading…
Reference in New Issue
Block a user