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

Input guard in generateSyntheticSpans: the synthetic-load generator attributes every span to a model name drawn from cfg.models, and an empty list leaves nothing to sample. It fires before any span is created, so no partial data is produced.

Solutions

  1. Provide at least one model name in cfg.models
  2. Default to a fixed model list when the caller omits one
  3. Validate the config once at CLI entry and report all missing fields together
Defensive patterns

Strategy: validation

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.

Appendix: 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)