{"record":{"id":"c5ba3bf6ba59f6ee","repo":"Hmbown/CodeWhale","slug":"import-exceeds-the-maxevents-tolocalestring-event-limit-c5ba3b","errorCode":null,"errorMessage":"Import exceeds the ${maxEvents.toLocaleString()} event limit.","messagePattern":"Import exceeds the (.+?) event limit\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/ingest.ts","lineNumber":165,"sourceCode":"    links: list(a.links).filter(x => typeof x?.traceId === 'string' && typeof x?.spanId === 'string'),\n    attributes: at, payload: a.payload, raw: a.raw ?? v,\n    observation: a.observation === undefined ? undefined : validateObservation(a.observation),\n  };\n}\ninterface OtlpRecord { span: Obj; resource: Obj; scope: Obj; resourceSchema?: string; scopeSchema?: string }\nfunction otlpRecords(doc: Obj): OtlpRecord[] {\n  const out: OtlpRecord[] = [];\n  for (const r of list(doc.resourceSpans)) {\n    for (const s of list(r.scopeSpans ?? r.instrumentationLibrarySpans)) {\n      for (const span of list(s.spans)) out.push({ span: obj(span), resource: obj(r.resource), scope: obj(s.scope ?? s.instrumentationLibrary), resourceSchema: r.schemaUrl, scopeSchema: s.schemaUrl });\n    }\n  }\n  return out;\n}\nfunction fromOTLP(doc: Obj, maxEvents: number): { events: WhaleEvent[]; origins: Map<string, string>; warnings: string[] } {\n  const records = otlpRecords(doc), bases = new Map<string, bigint>(), warnings: string[] = [];\n  if (!records.length) throw new Error('No spans found in resourceSpans[].scopeSpans[].spans[].');\n  if (records.length > maxEvents) throw new Error(`Import exceeds the ${maxEvents.toLocaleString()} event limit.`);\n  for (const { span: s } of records) {\n    if (!str(s.traceId) || !str(s.spanId)) throw new Error('Every OTLP span requires traceId and spanId.');\n    const start = ns(s.startTimeUnixNano, 'startTimeUnixNano');\n    const end = s.endTimeUnixNano === undefined ? start : ns(s.endTimeUnixNano, 'endTimeUnixNano');\n    if (end < start) throw new Error(`OTLP span ${s.spanId}: end precedes start.`);\n    let earliest = start;\n    for (const e of list(s.events)) { const t = ns(e.timeUnixNano, 'event.timeUnixNano'); if (t < earliest) earliest = t; }\n    if (!bases.has(s.traceId) || earliest < bases.get(s.traceId)!) bases.set(s.traceId, earliest);\n    if ((s.droppedEventsCount ?? 0) > 0) warnings.push(`Span ${s.spanId} reports ${s.droppedEventsCount} dropped events; coverage is incomplete.`);\n  }\n  const events: WhaleEvent[] = [];\n  for (const rec of records) {\n    const s = rec.span, a = { ...attributes(rec.resource.attributes), ...attributes(s.attributes) };\n    const origin = bases.get(s.traceId)!, start = ns(s.startTimeUnixNano, 'startTimeUnixNano');\n    const end = s.endTimeUnixNano === undefined ? start : ns(s.endTimeUnixNano, 'endTimeUnixNano');\n    const name = String(s.name ?? 'unnamed span');\n    const e: WhaleEvent = {\n      schemaVersion: 1, id: s.spanId, traceId: s.traceId, parentId: str(s.parentSpanId),","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/ingest.ts#L147-L183","documentation":"Import size cap in fromOTLP/ingest: the incoming OTLP document expands to more events than the configured maxEvents limit. The cap bounds memory and compile cost for a single import; the caller must split or trim the trace before importing it.","triggerScenarios":"Calling the OTLP import (via importTrace) with a document whose span count exceeds maxEvents (default 250000, configurable via ImportOptions.maxEvents within [1, 250000]).","commonSituations":"Bulk exports from long-running services; a collector dumping every span from a busy hour; forgetting to raise or intentionally cap maxEvents for very large exports.","solutions":["Split the export into smaller chunks, e.g. by trace, and import each separately.","Raise options.maxEvents up to the 250000 ceiling if your environment can handle it.","Filter spans at export time (sampling, time window) to reduce count below the limit."],"exampleFix":"// before\nimportTrace(text, 'big.json');\n// after\nimportTrace(text, 'big.json', { maxEvents: 250000 });","handlingStrategy":"validation","validationCode":"const spanCount = countOtlpSpans(text); // parse and count resourceSpans[].scopeSpans[].spans[]\nconst maxEvents = 250000;\nif (spanCount > maxEvents) throw new Error(`Split export: ${spanCount} spans exceeds ${maxEvents}`);","typeGuard":null,"tryCatchPattern":"try {\n  traces = importTrace(text, file, { maxEvents: 250000 });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('event limit')) {\n    console.error('Split the export by trace and import each chunk separately');\n  } else throw e;\n}","preventionTips":["Estimate export size/count before importing and split proactively by trace.","Configure collector sampling to bound span volume.","Remember the hard ceiling is 250000 events regardless of options."],"tags":["limits","otlp","ingest"],"backgroundTag":"file-size-limit-exceeded","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"}