mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Next/prev buttons * expand * Sticky search bar * Removed anys * testing * testing * Tests for next/prev/suffix * More tests * Span bar row color * Add clear to input and update search bar styles * Update test * PR changes Co-authored-by: Connor Lindsey <cblindsey3@gmail.com>
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { DataFrame, DataFrameView, TraceSpanRow } from '@grafana/data';
|
|
import { Trace, TraceProcess, TraceResponse, transformTraceData } from '@jaegertracing/jaeger-ui-components';
|
|
|
|
export function transformDataFrames(frame?: DataFrame): Trace | null {
|
|
if (!frame) {
|
|
return null;
|
|
}
|
|
let data: TraceResponse =
|
|
frame.fields.length === 1
|
|
? // For backward compatibility when we sent whole json response in a single field/value
|
|
frame.fields[0].values.get(0)
|
|
: transformTraceDataFrame(frame);
|
|
return transformTraceData(data);
|
|
}
|
|
|
|
function transformTraceDataFrame(frame: DataFrame): TraceResponse {
|
|
const view = new DataFrameView<TraceSpanRow>(frame);
|
|
const processes: Record<string, TraceProcess> = {};
|
|
for (let i = 0; i < view.length; i++) {
|
|
const span = view.get(i);
|
|
if (!processes[span.spanID]) {
|
|
processes[span.spanID] = {
|
|
serviceName: span.serviceName,
|
|
tags: span.serviceTags,
|
|
};
|
|
}
|
|
}
|
|
|
|
return {
|
|
traceID: view.get(0).traceID,
|
|
processes,
|
|
spans: view.toArray().map((s, index) => {
|
|
const references = [];
|
|
if (s.parentSpanID) {
|
|
references.push({ refType: 'CHILD_OF' as const, spanID: s.parentSpanID, traceID: s.traceID });
|
|
}
|
|
if (s.references) {
|
|
references.push(...s.references.map((reference) => ({ refType: 'FOLLOWS_FROM' as const, ...reference })));
|
|
}
|
|
return {
|
|
...s,
|
|
duration: s.duration * 1000,
|
|
startTime: s.startTime * 1000,
|
|
processID: s.spanID,
|
|
flags: 0,
|
|
references,
|
|
logs: s.logs?.map((l) => ({ ...l, timestamp: l.timestamp * 1000 })) || [],
|
|
dataFrameRowIndex: index,
|
|
};
|
|
}),
|
|
};
|
|
}
|