From 5a87d12e8c321e6680e187b2de0e80510fbfe672 Mon Sep 17 00:00:00 2001 From: Connor Lindsey Date: Thu, 31 Mar 2022 08:30:22 -0600 Subject: [PATCH] Tempo: Download span references in data inspector (#47074) * Tempo: Download span references in data inspector --- .../src/components/Table/JSONViewCell.tsx | 2 +- .../SpanDetail/AccordianReferences.tsx | 9 +- .../datasource/tempo/mockJsonResponse.json | 679 +++++++++++++++--- .../datasource/tempo/resultTransformer.ts | 29 + .../plugins/datasource/tempo/testResponse.ts | 69 +- 5 files changed, 694 insertions(+), 94 deletions(-) diff --git a/packages/grafana-ui/src/components/Table/JSONViewCell.tsx b/packages/grafana-ui/src/components/Table/JSONViewCell.tsx index 3a9904f026b..6efeb2feb10 100644 --- a/packages/grafana-ui/src/components/Table/JSONViewCell.tsx +++ b/packages/grafana-ui/src/components/Table/JSONViewCell.tsx @@ -29,7 +29,7 @@ export function JSONViewCell(props: TableCellProps): JSX.Element { return (
- {!link &&
{value}
} + {!link &&
{displayValue}
} {link && ( { content: attr(data-label); } `, + serviceName: css` + margin-right: 8px; + `, }; }; @@ -134,7 +137,9 @@ export function References(props: ReferenceItemProps) { {reference.span ? ( - {reference.span.process.serviceName} + + {reference.span.process.serviceName} + {reference.span.operationName} ) : ( diff --git a/public/app/plugins/datasource/tempo/mockJsonResponse.json b/public/app/plugins/datasource/tempo/mockJsonResponse.json index 0697ad16fee..31cae22d1e3 100644 --- a/public/app/plugins/datasource/tempo/mockJsonResponse.json +++ b/public/app/plugins/datasource/tempo/mockJsonResponse.json @@ -3,12 +3,42 @@ { "resource": { "attributes": [ - { "key": "service.name", "value": { "stringValue": "db" } }, - { "key": "job", "value": { "stringValue": "tns/db" } }, - { "key": "opencensus.exporterversion", "value": { "stringValue": "Jaeger-Go-2.22.1" } }, - { "key": "host.name", "value": { "stringValue": "63d16772b4a2" } }, - { "key": "ip", "value": { "stringValue": "172.24.0.2" } }, - { "key": "client-uuid", "value": { "stringValue": "39fb01637a579639" } } + { + "key": "service.name", + "value": { + "stringValue": "db" + } + }, + { + "key": "job", + "value": { + "stringValue": "tns/db" + } + }, + { + "key": "opencensus.exporterversion", + "value": { + "stringValue": "Jaeger-Go-2.22.1" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "63d16772b4a2" + } + }, + { + "key": "ip", + "value": { + "stringValue": "172.24.0.2" + } + }, + { + "key": "client-uuid", + "value": { + "stringValue": "39fb01637a579639" + } + } ] }, "instrumentationLibrarySpans": [ @@ -24,10 +54,55 @@ "startTimeUnixNano": "1627471657255809000", "endTimeUnixNano": "1627471657256268000", "attributes": [ - { "key": "http.status_code", "value": { "intValue": "200" } }, - { "key": "http.method", "value": { "stringValue": "GET" } }, - { "key": "http.url", "value": { "stringValue": "/" } }, - { "key": "component", "value": { "stringValue": "net/http" } } + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + }, + { + "key": "http.method", + "value": { + "stringValue": "GET" + } + }, + { + "key": "http.url", + "value": { + "stringValue": "/" + } + }, + { + "key": "component", + "value": { + "stringValue": "net/http" + } + } + ], + "links": [ + { + "spanId": "spanId", + "traceId": "traceId", + "attributes": [ + { + "key": "key", + "value": { + "stringValue": "Value" + } + }, + { + "key": "intValue", + "value": { + "intValue": 4 + } + } + ] + }, + { + "spanId": "spanId2", + "traceId": "traceId2", + "attributes": [] + } ], "status": {} } @@ -38,12 +113,42 @@ { "resource": { "attributes": [ - { "key": "service.name", "value": { "stringValue": "app" } }, - { "key": "job", "value": { "stringValue": "tns/app" } }, - { "key": "opencensus.exporterversion", "value": { "stringValue": "Jaeger-Go-2.22.1" } }, - { "key": "host.name", "value": { "stringValue": "f68212e86151" } }, - { "key": "ip", "value": { "stringValue": "172.24.0.7" } }, - { "key": "client-uuid", "value": { "stringValue": "8b6e8600b53a24" } } + { + "key": "service.name", + "value": { + "stringValue": "app" + } + }, + { + "key": "job", + "value": { + "stringValue": "tns/app" + } + }, + { + "key": "opencensus.exporterversion", + "value": { + "stringValue": "Jaeger-Go-2.22.1" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "f68212e86151" + } + }, + { + "key": "ip", + "value": { + "stringValue": "172.24.0.7" + } + }, + { + "key": "client-uuid", + "value": { + "stringValue": "8b6e8600b53a24" + } + } ] }, "instrumentationLibrarySpans": [ @@ -66,12 +171,42 @@ { "resource": { "attributes": [ - { "key": "service.name", "value": { "stringValue": "lb" } }, - { "key": "job", "value": { "stringValue": "tns/loadgen" } }, - { "key": "opencensus.exporterversion", "value": { "stringValue": "Jaeger-Go-2.22.1" } }, - { "key": "host.name", "value": { "stringValue": "6475ba6d3c8b" } }, - { "key": "ip", "value": { "stringValue": "172.24.0.8" } }, - { "key": "client-uuid", "value": { "stringValue": "535eb863d7ade742" } } + { + "key": "service.name", + "value": { + "stringValue": "lb" + } + }, + { + "key": "job", + "value": { + "stringValue": "tns/loadgen" + } + }, + { + "key": "opencensus.exporterversion", + "value": { + "stringValue": "Jaeger-Go-2.22.1" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "6475ba6d3c8b" + } + }, + { + "key": "ip", + "value": { + "stringValue": "172.24.0.8" + } + }, + { + "key": "client-uuid", + "value": { + "stringValue": "535eb863d7ade742" + } + } ] }, "instrumentationLibrarySpans": [ @@ -85,8 +220,18 @@ "startTimeUnixNano": "1627471657247632000", "endTimeUnixNano": "1627471657260233000", "attributes": [ - { "key": "sampler.type", "value": { "stringValue": "const" } }, - { "key": "sampler.param", "value": { "boolValue": true } } + { + "key": "sampler.type", + "value": { + "stringValue": "const" + } + }, + { + "key": "sampler.param", + "value": { + "boolValue": true + } + } ], "status": {} } @@ -97,12 +242,42 @@ { "resource": { "attributes": [ - { "key": "service.name", "value": { "stringValue": "lb" } }, - { "key": "job", "value": { "stringValue": "tns/loadgen" } }, - { "key": "opencensus.exporterversion", "value": { "stringValue": "Jaeger-Go-2.22.1" } }, - { "key": "host.name", "value": { "stringValue": "6475ba6d3c8b" } }, - { "key": "ip", "value": { "stringValue": "172.24.0.8" } }, - { "key": "client-uuid", "value": { "stringValue": "535eb863d7ade742" } } + { + "key": "service.name", + "value": { + "stringValue": "lb" + } + }, + { + "key": "job", + "value": { + "stringValue": "tns/loadgen" + } + }, + { + "key": "opencensus.exporterversion", + "value": { + "stringValue": "Jaeger-Go-2.22.1" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "6475ba6d3c8b" + } + }, + { + "key": "ip", + "value": { + "stringValue": "172.24.0.8" + } + }, + { + "key": "client-uuid", + "value": { + "stringValue": "535eb863d7ade742" + } + } ] }, "instrumentationLibrarySpans": [ @@ -118,67 +293,189 @@ "startTimeUnixNano": "1627471657247674000", "endTimeUnixNano": "1627471657261178000", "attributes": [ - { "key": "http.status_code", "value": { "intValue": "200" } }, - { "key": "component", "value": { "stringValue": "net/http" } }, - { "key": "http.method", "value": { "stringValue": "GET" } }, - { "key": "http.url", "value": { "stringValue": "app:80" } }, - { "key": "net/http.reused", "value": { "boolValue": false } }, - { "key": "net/http.was_idle", "value": { "boolValue": false } } + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + }, + { + "key": "component", + "value": { + "stringValue": "net/http" + } + }, + { + "key": "http.method", + "value": { + "stringValue": "GET" + } + }, + { + "key": "http.url", + "value": { + "stringValue": "app:80" + } + }, + { + "key": "net/http.reused", + "value": { + "boolValue": false + } + }, + { + "key": "net/http.was_idle", + "value": { + "boolValue": false + } + } ], "events": [ { "timeUnixNano": "1627471657247711000", - "attributes": [{ "key": "event", "value": { "stringValue": "GetConn" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "GetConn" + } + } + ] }, { "timeUnixNano": "1627471657247822000", "attributes": [ - { "key": "event", "value": { "stringValue": "DNSStart" } }, - { "key": "host", "value": { "stringValue": "app" } } + { + "key": "event", + "value": { + "stringValue": "DNSStart" + } + }, + { + "key": "host", + "value": { + "stringValue": "app" + } + } ] }, { "timeUnixNano": "1627471657249309000", "attributes": [ - { "key": "event", "value": { "stringValue": "DNSDone" } }, - { "key": "addr", "value": { "stringValue": "172.24.0.7" } } + { + "key": "event", + "value": { + "stringValue": "DNSDone" + } + }, + { + "key": "addr", + "value": { + "stringValue": "172.24.0.7" + } + } ] }, { "timeUnixNano": "1627471657249395000", "attributes": [ - { "key": "event", "value": { "stringValue": "ConnectStart" } }, - { "key": "network", "value": { "stringValue": "tcp" } }, - { "key": "addr", "value": { "stringValue": "172.24.0.7:80" } } + { + "key": "event", + "value": { + "stringValue": "ConnectStart" + } + }, + { + "key": "network", + "value": { + "stringValue": "tcp" + } + }, + { + "key": "addr", + "value": { + "stringValue": "172.24.0.7:80" + } + } ] }, { "timeUnixNano": "1627471657250250000", "attributes": [ - { "key": "event", "value": { "stringValue": "ConnectDone" } }, - { "key": "network", "value": { "stringValue": "tcp" } }, - { "key": "addr", "value": { "stringValue": "172.24.0.7:80" } } + { + "key": "event", + "value": { + "stringValue": "ConnectDone" + } + }, + { + "key": "network", + "value": { + "stringValue": "tcp" + } + }, + { + "key": "addr", + "value": { + "stringValue": "172.24.0.7:80" + } + } ] }, { "timeUnixNano": "1627471657250313000", - "attributes": [{ "key": "event", "value": { "stringValue": "GotConn" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "GotConn" + } + } + ] }, { "timeUnixNano": "1627471657250446000", - "attributes": [{ "key": "event", "value": { "stringValue": "WroteHeaders" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "WroteHeaders" + } + } + ] }, { "timeUnixNano": "1627471657250465000", - "attributes": [{ "key": "event", "value": { "stringValue": "WroteRequest" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "WroteRequest" + } + } + ] }, { "timeUnixNano": "1627471657260087000", - "attributes": [{ "key": "event", "value": { "stringValue": "GotFirstResponseByte" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "GotFirstResponseByte" + } + } + ] }, { "timeUnixNano": "1627471657260804000", - "attributes": [{ "key": "event", "value": { "stringValue": "ClosedBody" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "ClosedBody" + } + } + ] } ], "status": {} @@ -190,12 +487,42 @@ { "resource": { "attributes": [ - { "key": "service.name", "value": { "stringValue": "app" } }, - { "key": "job", "value": { "stringValue": "tns/app" } }, - { "key": "opencensus.exporterversion", "value": { "stringValue": "Jaeger-Go-2.22.1" } }, - { "key": "host.name", "value": { "stringValue": "f68212e86151" } }, - { "key": "ip", "value": { "stringValue": "172.24.0.7" } }, - { "key": "client-uuid", "value": { "stringValue": "8b6e8600b53a24" } } + { + "key": "service.name", + "value": { + "stringValue": "app" + } + }, + { + "key": "job", + "value": { + "stringValue": "tns/app" + } + }, + { + "key": "opencensus.exporterversion", + "value": { + "stringValue": "Jaeger-Go-2.22.1" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "f68212e86151" + } + }, + { + "key": "ip", + "value": { + "stringValue": "172.24.0.7" + } + }, + { + "key": "client-uuid", + "value": { + "stringValue": "8b6e8600b53a24" + } + } ] }, "instrumentationLibrarySpans": [ @@ -211,67 +538,189 @@ "startTimeUnixNano": "1627471657251445000", "endTimeUnixNano": "1627471657260828000", "attributes": [ - { "key": "http.status_code", "value": { "intValue": "200" } }, - { "key": "component", "value": { "stringValue": "net/http" } }, - { "key": "http.method", "value": { "stringValue": "GET" } }, - { "key": "http.url", "value": { "stringValue": "db:80" } }, - { "key": "net/http.reused", "value": { "boolValue": false } }, - { "key": "net/http.was_idle", "value": { "boolValue": false } } + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + }, + { + "key": "component", + "value": { + "stringValue": "net/http" + } + }, + { + "key": "http.method", + "value": { + "stringValue": "GET" + } + }, + { + "key": "http.url", + "value": { + "stringValue": "db:80" + } + }, + { + "key": "net/http.reused", + "value": { + "boolValue": false + } + }, + { + "key": "net/http.was_idle", + "value": { + "boolValue": false + } + } ], "events": [ { "timeUnixNano": "1627471657251575000", - "attributes": [{ "key": "event", "value": { "stringValue": "GetConn" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "GetConn" + } + } + ] }, { "timeUnixNano": "1627471657251700000", "attributes": [ - { "key": "event", "value": { "stringValue": "DNSStart" } }, - { "key": "host", "value": { "stringValue": "db" } } + { + "key": "event", + "value": { + "stringValue": "DNSStart" + } + }, + { + "key": "host", + "value": { + "stringValue": "db" + } + } ] }, { "timeUnixNano": "1627471657254144000", "attributes": [ - { "key": "event", "value": { "stringValue": "DNSDone" } }, - { "key": "addr", "value": { "stringValue": "172.24.0.2" } } + { + "key": "event", + "value": { + "stringValue": "DNSDone" + } + }, + { + "key": "addr", + "value": { + "stringValue": "172.24.0.2" + } + } ] }, { "timeUnixNano": "1627471657254295000", "attributes": [ - { "key": "event", "value": { "stringValue": "ConnectStart" } }, - { "key": "network", "value": { "stringValue": "tcp" } }, - { "key": "addr", "value": { "stringValue": "172.24.0.2:80" } } + { + "key": "event", + "value": { + "stringValue": "ConnectStart" + } + }, + { + "key": "network", + "value": { + "stringValue": "tcp" + } + }, + { + "key": "addr", + "value": { + "stringValue": "172.24.0.2:80" + } + } ] }, { "timeUnixNano": "1627471657255054000", "attributes": [ - { "key": "event", "value": { "stringValue": "ConnectDone" } }, - { "key": "network", "value": { "stringValue": "tcp" } }, - { "key": "addr", "value": { "stringValue": "172.24.0.2:80" } } + { + "key": "event", + "value": { + "stringValue": "ConnectDone" + } + }, + { + "key": "network", + "value": { + "stringValue": "tcp" + } + }, + { + "key": "addr", + "value": { + "stringValue": "172.24.0.2:80" + } + } ] }, { "timeUnixNano": "1627471657255199000", - "attributes": [{ "key": "event", "value": { "stringValue": "GotConn" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "GotConn" + } + } + ] }, { "timeUnixNano": "1627471657255257000", - "attributes": [{ "key": "event", "value": { "stringValue": "WroteHeaders" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "WroteHeaders" + } + } + ] }, { "timeUnixNano": "1627471657255274000", - "attributes": [{ "key": "event", "value": { "stringValue": "WroteRequest" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "WroteRequest" + } + } + ] }, { "timeUnixNano": "1627471657258308000", - "attributes": [{ "key": "event", "value": { "stringValue": "GotFirstResponseByte" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "GotFirstResponseByte" + } + } + ] }, { "timeUnixNano": "1627471657260811000", - "attributes": [{ "key": "event", "value": { "stringValue": "ClosedBody" } }] + "attributes": [ + { + "key": "event", + "value": { + "stringValue": "ClosedBody" + } + } + ] } ], "status": {} @@ -283,12 +732,42 @@ { "resource": { "attributes": [ - { "key": "service.name", "value": { "stringValue": "app" } }, - { "key": "job", "value": { "stringValue": "tns/app" } }, - { "key": "opencensus.exporterversion", "value": { "stringValue": "Jaeger-Go-2.22.1" } }, - { "key": "host.name", "value": { "stringValue": "f68212e86151" } }, - { "key": "ip", "value": { "stringValue": "172.24.0.7" } }, - { "key": "client-uuid", "value": { "stringValue": "8b6e8600b53a24" } } + { + "key": "service.name", + "value": { + "stringValue": "app" + } + }, + { + "key": "job", + "value": { + "stringValue": "tns/app" + } + }, + { + "key": "opencensus.exporterversion", + "value": { + "stringValue": "Jaeger-Go-2.22.1" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "f68212e86151" + } + }, + { + "key": "ip", + "value": { + "stringValue": "172.24.0.7" + } + }, + { + "key": "client-uuid", + "value": { + "stringValue": "8b6e8600b53a24" + } + } ] }, "instrumentationLibrarySpans": [ @@ -304,10 +783,30 @@ "startTimeUnixNano": "1627471657251228000", "endTimeUnixNano": "1627471657260930000", "attributes": [ - { "key": "http.status_code", "value": { "intValue": "200" } }, - { "key": "http.method", "value": { "stringValue": "GET" } }, - { "key": "http.url", "value": { "stringValue": "/" } }, - { "key": "component", "value": { "stringValue": "net/http" } } + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + }, + { + "key": "http.method", + "value": { + "stringValue": "GET" + } + }, + { + "key": "http.url", + "value": { + "stringValue": "/" + } + }, + { + "key": "component", + "value": { + "stringValue": "net/http" + } + } ], "status": {} } diff --git a/public/app/plugins/datasource/tempo/resultTransformer.ts b/public/app/plugins/datasource/tempo/resultTransformer.ts index 8902cc1025d..89859c62a23 100644 --- a/public/app/plugins/datasource/tempo/resultTransformer.ts +++ b/public/app/plugins/datasource/tempo/resultTransformer.ts @@ -390,6 +390,7 @@ export function transformToOTLP(data: MutableDataFrame): { droppedLinksCount: 0, status: getOTLPStatus(span.tags), events: getOTLPEvents(span.logs), + links: getOTLPReferences(span.references), }); } @@ -502,6 +503,34 @@ function getOTLPEvents(logs: TraceLog[]): collectorTypes.opentelemetryProto.trac return events; } +function getOTLPReferences( + references: TraceSpanReference[] +): collectorTypes.opentelemetryProto.trace.v1.Span.Link[] | undefined { + if (!references || !references.length) { + return undefined; + } + + let links: collectorTypes.opentelemetryProto.trace.v1.Span.Link[] = []; + for (const ref of references) { + let link: collectorTypes.opentelemetryProto.trace.v1.Span.Link = { + traceId: ref.traceID, + spanId: ref.spanID, + attributes: [], + droppedAttributesCount: 0, + }; + if (ref.tags?.length) { + for (const tag of ref.tags) { + link.attributes?.push({ + key: tag.key, + value: toAttributeValue(tag), + }); + } + } + links.push(link); + } + return links; +} + export function transformTrace(response: DataQueryResponse, nodeGraph = false): DataQueryResponse { // We need to parse some of the fields which contain stringified json. // Seems like we can't just map the values as the frame we got from backend has some default processing diff --git a/public/app/plugins/datasource/tempo/testResponse.ts b/public/app/plugins/datasource/tempo/testResponse.ts index eb922a36c8c..3e5fa4ccbdc 100644 --- a/public/app/plugins/datasource/tempo/testResponse.ts +++ b/public/app/plugins/datasource/tempo/testResponse.ts @@ -1928,7 +1928,23 @@ export const otlpDataFrameFromResponse = new MutableDataFrame({ type: 'other', config: {}, labels: undefined, - values: [[]], + values: [ + [ + { + spanID: 'spanId', + traceID: 'traceId', + tags: [ + { key: 'key', value: 'Value' }, + { key: 'intValue', value: 4 }, + ], + }, + { + spanID: 'spanId2', + traceID: 'traceId2', + tags: [], + }, + ], + ], state: { displayName: 'references', }, @@ -2118,6 +2134,32 @@ export const otlpDataFrameToResponse = new MutableDataFrame({ displayName: 'tags', }, }, + { + name: 'references', + type: 'other', + config: {}, + labels: undefined, + values: [ + [ + { + spanID: 'spanId', + traceID: 'traceId', + tags: [ + { key: 'key', value: 'Value' }, + { key: 'intValue', value: 4 }, + ], + }, + { + spanID: 'spanId2', + traceID: 'traceId2', + tags: [], + }, + ], + ], + state: { + displayName: 'references', + }, + }, ], first: ['60ba2abb44f13eae'], length: 1, @@ -2153,6 +2195,31 @@ export const otlpResponse = { { key: 'http.url', value: { stringValue: '/' } }, { key: 'component', value: { stringValue: 'net/http' } }, ], + links: [ + { + spanId: 'spanId', + traceId: 'traceId', + attributes: [ + { + key: 'key', + value: { + stringValue: 'Value', + }, + }, + { + key: 'intValue', + value: { + intValue: 4, + }, + }, + ], + }, + { + spanId: 'spanId2', + traceId: 'traceId2', + attributes: [], + }, + ], }, ], },