{"record":{"id":"cff5b22beb53945b","repo":"Hmbown/CodeWhale","slug":"this-import-contains-more-than-maxtraces-traces-split-it-by","errorCode":null,"errorMessage":"This import contains more than ${maxTraces} traces. Split it by trace ID.","messagePattern":"This import contains more than (.+?) traces\\. Split it by trace ID\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/ingest.ts","lineNumber":266,"sourceCode":"    trace.events = trace.events.map(e => privacyEvent(e, mode));\n    return [trace];\n  }\n  const isOTLP = Array.isArray(root.resourceSpans);\n  let all: WhaleEvent[], origins = new Map<string, string>(), warnings: string[] = [];\n  if (isOTLP) { const r = fromOTLP(root, maxEvents); all = r.events; origins = r.origins; warnings = r.warnings; }\n  else {\n    const incoming = records ?? [safe];\n    if (incoming.length > maxEvents) throw new Error(`Import exceeds the ${maxEvents.toLocaleString()} event limit.`);\n    all = incoming.map(normalizedEvent);\n  }\n  if (!all.length) throw new Error('The file contains no events.');\n  const groups = new Map<string, WhaleEvent[]>(), ids = new Set<string>();\n  for (const e of all) {\n    const key = `${e.traceId}\\0${e.id}`;\n    if (ids.has(key)) throw new Error(`Duplicate event identity (${e.traceId}, ${e.id}). Import cancelled.`);\n    ids.add(key);\n    const group = groups.get(e.traceId) ?? []; group.push(privacyEvent(e, mode)); groups.set(e.traceId, group);\n    if (groups.size > maxTraces) throw new Error(`This import contains more than ${maxTraces} traces. Split it by trace ID.`);\n  }\n  return [...groups].map(([id, events]) => {\n    events.sort((a, b) => a.startTime - b.startTime || a.id.localeCompare(b.id));\n    const base = isOTLP ? 0 : events[0].startTime;\n    if (!isOTLP && events.some(e => Math.abs(e.endTime - base) > Number.MAX_SAFE_INTEGER)) throw new Error('Trace duration exceeds safely representable milliseconds.');\n    for (const e of events) {\n      if (e.attributes['whalesong.error_onset_ms'] !== undefined) e.attributes['whalesong.error_onset_ms'] = errorOnsetOf(e) - base;\n      e.startTime -= base; e.endTime -= base;\n    }\n    const localIds = new Set(events.map(e => e.id)), missingParents = events.filter(e => e.parentId && !localIds.has(e.parentId)).length;\n    const traceWarnings = [...warnings];\n    if (missingParents) traceWarnings.push(`${missingParents} parent spans are absent from this trace; no parent relationship was invented.`);\n    if (events.some(e => e.openEnded)) traceWarnings.push('Open spans have unknown duration and are displayed as onset-only, not extended into invented activity.');\n    const currencies = new Set(events.filter(e => e.cost !== undefined).map(e => e.costCurrency ?? 'unspecified'));\n    if (currencies.size > 1) traceWarnings.push('Mixed cost currencies: aggregate cost comparison is disabled.');\n    return { id, name: groups.size > 1 ? `${filename} · ${id.slice(0, 8)}` : String(root.name ?? filename),\n      events, duration: Math.max(1, events.reduce((m, e) => Math.max(m, e.endTime, e.startTime, e.status === 'error' ? errorOnsetOf(e) : 0), 0)),\n      originTime: origins.get(id) ?? (root.originTime !== undefined && base === 0 ? str(root.originTime) : `${base} ms`),","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/ingest.ts#L248-L284","documentation":"A single import may contain at most options.maxTraces (default 8, hard cap 64) distinct trace IDs. When the input's trace count exceeds that, importTrace aborts and asks you to split the file by trace ID, keeping memory and UI cost bounded per import.","triggerScenarios":"importTrace on a combined export containing more distinct traceId values than maxTraces (e.g. 20 traces with default 8); lowering maxTraces below the actual trace count in the file.","commonSituations":"Exporting a whole service's spans instead of selected traces; concatenating many exports; a caller setting maxTraces to 1 to import one trace at a time but passing a multi-trace file.","solutions":["Split the file by trace ID and import each group with its own importTrace call.","Raise options.maxTraces (integer, max 64) to fit the trace count.","Filter the export to only the traces you need before importing."],"exampleFix":"// before\nimportTrace(text, name, { maxTraces: 8 }); // file has 20 traces\n// after\nimportTrace(text, name, { maxTraces: 64 }); // or split by trace ID\n","handlingStrategy":"validation","validationCode":"const traceIds = new Set(events.map(e => e.traceId));\nif (traceIds.size > 64) throw new Error(`${traceIds.size} traces exceed the 64-trace cap; split the file.`);","typeGuard":null,"tryCatchPattern":"try {\n  importTrace(text, name, { maxTraces });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Split it by trace ID')) {\n    console.error(`File has more than ${maxTraces} traces; split or raise maxTraces (<=64).`);\n  }\n}","preventionTips":["Count distinct traceId values in the file before import.","Split large exports by trace ID at export time.","Raise maxTraces up to 64 if you really need many traces in one call.","Filter exports to the traces you intend to inspect."],"tags":["validation","limits","ingest"],"backgroundTag":"value-out-of-range","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}