rohitg00/ai-engineering-from-scratch · error · Error

generateSyntheticSpans: cfg.models must not be empty

Error message

generateSyntheticSpans: cfg.models must not be empty

What it means

Error "generateSyntheticSpans: cfg.models must not be empty" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at phases/19-capstone-projects/11-llm-observability-dashboard/code/ts/src/index.ts:29

 * Schema: OpenTelemetry GenAI semantic conventions
 *   https://opentelemetry.io/docs/specs/semconv/gen-ai/
 */

import { serve } from "@hono/node-server";
import { rollUpByModel } from "./rollup.js";
import { buildApp } from "./server.js";
import { ObservabilityStore } from "./spans.js";
import type { GenAISpan, ModelRollup } from "./types.js";

type SyntheticConfig = {
  spans: number;
  errorRate: number;
  models: string[];
};

export function generateSyntheticSpans(cfg: SyntheticConfig): GenAISpan[] {
  if (cfg.models.length === 0) {
    throw new Error("generateSyntheticSpans: cfg.models must not be empty");
  }
  const now = Date.now() * 1e6;
  const out: GenAISpan[] = [];
  for (let i = 0; i < cfg.spans; i++) {
    const model = cfg.models[i % cfg.models.length]!;
    if (!model) continue;
    const baseLatencyMs = 400 + ((i * 31) % 1800);
    const inputTokens = 200 + ((i * 17) % 4000);
    const outputTokens = 120 + ((i * 23) % 800);
    const isError =
      i % Math.max(1, Math.round(1 / cfg.errorRate)) === 0 && i > 0;
    out.push({
      trace_id: `trace-${i.toString(16).padStart(8, "0")}`,
      span_id: `span-${i.toString(16).padStart(8, "0")}`,
      name: "chat.completion",
      start_time_unix_nano: now + i * 1_000_000,
      end_time_unix_nano: now + i * 1_000_000 + baseLatencyMs * 1e6,
      status: isError ? "ERROR" : "OK",

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at phases/19-capstone-projects/11-llm-observability-dashboard/code/ts/src/index.ts:29 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/03aeae98aff46289. Report an issue: GitHub.