diff --git a/packages/jaeger-ui/src/model/transform-trace-data.test.js b/packages/jaeger-ui/src/model/transform-trace-data.test.js index 99c2bbad25..8dfa857fdc 100644 --- a/packages/jaeger-ui/src/model/transform-trace-data.test.js +++ b/packages/jaeger-ui/src/model/transform-trace-data.test.js @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { orderTags, deduplicateTags } from './transform-trace-data'; +import transformTraceData, { orderTags, deduplicateTags } from './transform-trace-data'; describe('orderTags()', () => { it('correctly orders tags', () => { @@ -53,3 +53,111 @@ describe('deduplicateTags()', () => { expect(tagsInfo.warnings).toEqual(['Duplicate tag "b.ip:8.8.4.4"']); }); }); + +describe('transformTraceData()', () => { + const startTime = 1586160015434000; + const duration = 34000; + const traceID = 'f77950feed55c1ce91dd8e87896623a6'; + const rootSpanID = 'd4dcb46e95b781f5'; + const rootOperationName = 'rootOperation'; + const serviceName = 'serviceName'; + + const spans = [ + { + traceID, + spanID: '41f71485ed2593e4', + operationName: 'someOperationName', + references: [ + { + refType: 'CHILD_OF', + traceID, + spanID: rootSpanID, + }, + ], + startTime, + duration, + tags: [], + processID: 'p1', + }, + { + traceID, + spanID: '4f623fd33c213cba', + operationName: 'anotherOperationName', + references: [ + { + refType: 'CHILD_OF', + traceID, + spanID: rootSpanID, + }, + ], + startTime: startTime + 100, + duration, + tags: [], + processID: 'p1', + }, + ]; + + const rootSpanWithMissingRef = { + traceID, + spanID: rootSpanID, + operationName: rootOperationName, + references: [ + { + refType: 'CHILD_OF', + traceID, + spanID: 'missingSpanId', + }, + ], + startTime: startTime + 50, + duration, + tags: [], + processID: 'p1', + }; + + const rootSpanWithoutRefs = { + traceID, + spanID: rootSpanID, + operationName: rootOperationName, + startTime: startTime + 50, + duration, + tags: [], + processID: 'p1', + }; + + const processes = { + p1: { + serviceName, + tags: [], + }, + }; + + it('should return null for trace without traceID', () => { + const traceData = { + traceID: undefined, + processes, + spans, + }; + + expect(transformTraceData(traceData)).toEqual(null); + }); + + it('should return trace data with correct traceName based on root span with missing ref', () => { + const traceData = { + traceID, + processes, + spans: [...spans, rootSpanWithMissingRef], + }; + + expect(transformTraceData(traceData).traceName).toEqual(`${serviceName}: ${rootOperationName}`); + }); + + it('should return trace data with correct traceName based on root span without any refs', () => { + const traceData = { + traceID, + processes, + spans: [...spans, rootSpanWithoutRefs], + }; + + expect(transformTraceData(traceData).traceName).toEqual(`${serviceName}: ${rootOperationName}`); + }); +}); diff --git a/packages/jaeger-ui/src/model/transform-trace-data.tsx b/packages/jaeger-ui/src/model/transform-trace-data.tsx index 04e0615515..3ec49f73ce 100644 --- a/packages/jaeger-ui/src/model/transform-trace-data.tsx +++ b/packages/jaeger-ui/src/model/transform-trace-data.tsx @@ -16,6 +16,7 @@ import _isEqual from 'lodash/isEqual'; import { getTraceSpanIdsAsTree } from '../selectors/trace'; import { getConfigValue } from '../utils/config/get-config'; +import { getTraceName } from './trace-viewer'; import { KeyValuePair, Span, SpanData, Trace, TraceData } from '../types/trace'; import TreeNode from '../utils/TreeNode'; @@ -120,7 +121,6 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[] const tree = getTraceSpanIdsAsTree(data); const spans: Span[] = []; const svcCounts: Record = {}; - let traceName = ''; tree.walk((spanID: string, node: TreeNode, depth: number = 0) => { if (spanID === '__root__') { @@ -132,9 +132,6 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[] } const { serviceName } = span.process; svcCounts[serviceName] = (svcCounts[serviceName] || 0) + 1; - if (!span.references || !span.references.length) { - traceName = `${serviceName}: ${span.operationName}`; - } span.relativeStartTime = span.startTime - traceStartTime; span.depth = depth - 1; span.hasChildren = node.children.length > 0; @@ -163,6 +160,7 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[] }); spans.push(span); }); + const traceName = getTraceName(spans); const services = Object.keys(svcCounts).map(name => ({ name, numberOfSpans: svcCounts[name] })); return { services,