{"record":{"id":"a2979eb02c9c424d","repo":"openzipkin/zipkin","slug":"list-span-implies-at-least-traceid-and-id-fields","errorCode":null,"errorMessage":"List<Span> implies at least traceId and id fields","messagePattern":"List<Span> implies at least traceId and id fields","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"zipkin-lens/src/util/trace.js","lineNumber":11,"sourceCode":"/*\n * Copyright The OpenZipkin Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nexport const ensureV2TraceData = (trace) => {\n  if (!Array.isArray(trace) || trace.length === 0) {\n    throw new Error('input is not a list');\n  }\n  const [first] = trace;\n  if (!first.traceId || !first.id) {\n    throw new Error('List<Span> implies at least traceId and id fields');\n  }\n  if (\n    first.binaryAnnotations ||\n    (!first.localEndpoint && !first.remoteEndpoint && !first.tags)\n  ) {\n    throw new Error(\n      'v1 format is not supported. For help, contact https://gitter.im/openzipkin/zipkin',\n    );\n  }\n};\n\nexport const hasRootSpan = (trace) => {\n  switch (trace.length) {\n    case 0:\n      return false;\n    case 1:\n      return true;\n    default:","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-lens/src/util/trace.js#L1-L29","documentation":"Thrown by zipkin-lens's ensureV2TraceData when the input is a non-empty array but its first element lacks a truthy traceId or id. Every Zipkin span (v2 format) must carry at least traceId and id; this check catches arrays whose elements are not span objects before the UI tries to build a span tree.","triggerScenarios":"Calling ensureV2TraceData on an array whose first element is missing traceId or id, e.g. [{name:\"op\"}], [{}], or an array of strings/numbers. Falsy values (empty string, undefined, null) also trigger it.","commonSituations":"Array of annotation objects or log entries mistakenly fed as spans; truncated/partial JSON where fields were dropped; a list of parsed CSV rows or heterogeneous objects; test fixtures with incomplete span shapes.","solutions":["Ensure every element of the array is a v2 span with non-empty traceId and id hex strings.","Filter out non-span entries before validation: arr.filter(s => s && s.traceId && s.id).","Regenerate the fixture/data from a real Zipkin server response so span shape is correct."],"exampleFix":"// before\nensureV2TraceData([{ name: 'get', duration: 10 }]); // throws\n\n// after\nconst spans = raw.filter((s) => s && s.traceId && s.id);\nensureV2TraceData(spans);","handlingStrategy":"validation","validationCode":"const hasRequiredIds = (arr) => arr.every((s) => s && s.traceId && s.id);\nif (!hasRequiredIds(spans)) throw new TypeError('every span needs traceId and id');","typeGuard":"const isV2Span = (s) => typeof s === 'object' && s !== null && typeof s.traceId === 'string' && typeof s.id === 'string' && s.traceId.length > 0 && s.id.length > 0;","tryCatchPattern":null,"preventionTips":["Filter inbound data to objects with traceId/id before validation.","Type trace data at the boundary (TS: interface Span { traceId: string; id: string; ... })."],"tags":["zipkin","javascript","validation","trace-data"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}