Tracing: Do not try to render trace view in dashboard if data missing (#76630)

* Check for process and span id

* Remove log

* Update tests

* Check for key
This commit is contained in:
Joey 2023-10-17 14:27:27 +01:00 committed by GitHub
parent f9484fcf82
commit 4c22027ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 2 deletions

View File

@ -143,6 +143,58 @@ describe('transformTraceData()', () => {
expect(transformTraceData(traceData)).toEqual(null);
});
it('should return null for any span without a spanID', () => {
const traceData = {
traceID,
processes,
spans: [
{
traceID,
operationName: 'rootOperation',
references: [
{
refType: 'CHILD_OF',
traceID,
spanID: rootSpanID,
},
],
startTime,
duration,
tags: [],
processID: 'p1',
},
],
} as unknown as TraceResponse;
expect(transformTraceData(traceData)).toEqual(null);
});
it('should return null for any span without a processID', () => {
const traceData = {
traceID,
processes,
spans: [
{
traceID,
spanID: '41f71485ed2593e4',
operationName: 'rootOperation',
references: [
{
refType: 'CHILD_OF',
traceID,
spanID: rootSpanID,
},
],
startTime,
duration,
tags: [],
},
],
} as unknown as TraceResponse;
expect(transformTraceData(traceData)).toEqual(null);
});
it('should return trace data with correct traceName based on root span with missing ref', () => {
const traceData = {
traceID,

View File

@ -74,7 +74,7 @@ export function orderTags(tags: TraceKeyValuePair[], topPrefixes?: string[]) {
* generally requires.
*/
export default function transformTraceData(data: TraceResponse | undefined): Trace | null {
if (!data?.traceID) {
if (!data?.traceID || data?.spans.some((x) => !x.processID || !x.spanID)) {
return null;
}
const traceID = data.traceID.toLowerCase();

View File

@ -46,7 +46,7 @@ class ColorGenerator {
_getColorIndex(key: string): number {
let i = this.cache.get(key);
if (i == null) {
const hash = this.hashCode(key.toLowerCase());
const hash = this.hashCode(key ? key.toLowerCase() : '');
i = Math.abs(hash % this.colorsHex.length);
if (this.prevColorIndex !== undefined) {