Skip to content

Commit

Permalink
Validate when tags and/or references fields are null
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 committed Jun 10, 2019
1 parent 2abec69 commit 0ad29df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 7 additions & 7 deletions packages/jaeger-ui/src/model/transform-trace-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
import _isEqual from 'lodash/isEqual';

import { getTraceSpanIdsAsTree } from '../selectors/trace';
import { KeyValuePair, Process, Span, SpanData, Trace, TraceData } from '../types/trace';
import { KeyValuePair, Span, SpanData, Trace, TraceData } from '../types/trace';
import TreeNode from '../utils/TreeNode';

type SpanWithProcess = SpanData & { process: Process };

function deduplicateTags(spanTags: Array<KeyValuePair>) {
const warningsHash: Map<string, string> = new Map<string, string>();
const tags: Array<KeyValuePair> = spanTags.reduce<Array<KeyValuePair>>((uniqueTags, tag) => {
Expand All @@ -38,7 +36,7 @@ function deduplicateTags(spanTags: Array<KeyValuePair>) {
* NOTE: Mutates `data` - Transform the HTTP response data into the form the app
* generally requires.
*/
export default function transformTraceData(data: TraceData & { spans: SpanWithProcess[] }): Trace | null {
export default function transformTraceData(data: TraceData & { spans: SpanData[] }): Trace | null {
let { traceID } = data;
if (!traceID) {
return null;
Expand All @@ -48,14 +46,14 @@ export default function transformTraceData(data: TraceData & { spans: SpanWithPr
let traceEndTime = 0;
let traceStartTime = Number.MAX_SAFE_INTEGER;
const spanIdCounts = new Map();
const spanMap = new Map<string, SpanWithProcess>();
const spanMap = new Map<string, Span>();
// filter out spans with empty start times
// eslint-disable-next-line no-param-reassign
data.spans = data.spans.filter(span => Boolean(span.startTime));

const max = data.spans.length;
for (let i = 0; i < max; i++) {
const span = data.spans[i];
const span: Span = data.spans[i] as Span;
const { startTime, duration, processID } = span;
//
let spanID = span.spanID;
Expand Down Expand Up @@ -107,9 +105,11 @@ export default function transformTraceData(data: TraceData & { spans: SpanWithPr
span.relativeStartTime = span.startTime - traceStartTime;
span.depth = depth - 1;
span.hasChildren = node.children.length > 0;
span.warnings = span.warnings || [];
span.tags = span.tags || [];
span.references = span.references || [];
const tagsInfo = deduplicateTags(span.tags);
span.tags = tagsInfo.tags;
span.warnings = span.warnings || [];
span.warnings = span.warnings.concat(tagsInfo.warnings);
span.references.forEach(ref => {
const refSpan = spanMap.get(ref.spanID) as Span;
Expand Down
9 changes: 6 additions & 3 deletions packages/jaeger-ui/src/types/trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ export type SpanData = {
startTime: number;
duration: number;
logs: Array<Log>;
tags: Array<KeyValuePair>;
references: Array<SpanReference>;
warnings: Array<string> | null;
tags?: Array<KeyValuePair>;
references?: Array<SpanReference>;
warnings?: Array<string> | null;
};

export type Span = SpanData & {
depth: number;
hasChildren: boolean;
process: Process;
relativeStartTime: number;
tags: NonNullable<SpanData['tags']>;
references: NonNullable<SpanData['references']>;
warnings: NonNullable<SpanData['warnings']>;
};

export type TraceData = {
Expand Down

0 comments on commit 0ad29df

Please sign in to comment.