This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ZeroEval TypeScript SDK — an observability, tracing, and monitoring platform SDK for AI products. Provides span-based tracing, automatic integrations (OpenAI, Vercel AI SDK, LangChain/LangGraph), signals, prompt management, and feedback APIs. Targets Node 18+, Bun, and browser environments. Dual ESM/CJS output.
npm run build # Build with tsup (ESM + CJS + .d.ts)
npm run watch # Build in watch mode for development
npm run clean # Remove dist/
npm test # Run all tests (vitest)
npm run test:core # Core tests only (tests/core/)
npm run test:perf # Performance tests only (tests/performance/)
npx vitest run tests/core/span.test.ts # Run a single test file
npm run lint # ESLint
npm run lint:fix # ESLint with auto-fix
npm run format # Prettier write
npm run format:check # Prettier check
npx tsc --noEmit # Type check without emittingThe SDK uses Node.js AsyncLocalStorage to maintain a span stack per async context, enabling automatic parent-child span relationships without explicit threading. Key flow:
init()(src/init.ts) configures the SDK and creates a singletonTracerTracer(src/observability/Tracer.ts) manages span lifecycle, buffering (default 100 spans), and periodic flushing (default 10s) to the backend viaBackendSpanWriterSpan(src/observability/Span.ts) represents a trace unit with UUID, trace/parent IDs, timing, tags, input/output, errors, and signals@spandecorator (src/observability/spanDecorator.ts) wraps functions to auto-capture args, return values, and errors — works as both method decorator and function wrapper
Client wrappers use proxy-based instrumentation for transparent tracing:
wrap()auto-detects client type (OpenAI vs Vercel AI) via type detection insrc/observability/integrations/wrapper.tswrapOpenAI()/wrapVercelAI()are type-specific wrappers- LangChain uses a callback handler pattern (
ZeroEvalCallbackHandler) exported fromzeroeval/langchain
src/index.ts— main SDK exports (init, span, wrap, signals, prompts, feedback)src/langchain.ts— LangChain-specific exports (callback handler, global handler management)
Both are built by tsup into dist/{index,langchain}.{js,cjs,d.ts}.
- Signals (src/signals.ts): Boolean/numerical/string metrics attached to spans, traces, or sessions
- Prompts (src/prompt.ts): Content-addressed by SHA-256 hash, supports versioning, template variable interpolation, and metadata embedding
- Feedback (src/feedback.ts): API for sending feedback on LLM completions
- Framework: Vitest with globals enabled (no imports needed for describe/it/expect)
- Pool: threads with
singleThread: true(required for AsyncLocalStorage correctness) - Setup:
vitest.setup.tsmocks integration utils and process.on to prevent side effects - Coverage threshold: 80% (lines, functions, branches, statements)
- Tests use
createTestTracer()from test setup helpers with mockBackendSpanWriter
- TypeScript strict mode with
experimentalDecorators: true @typescript-eslint/consistent-type-imports: error— useimport typefor type-only imports@typescript-eslint/no-floating-promises: error— all promises must be handled- Unused vars prefixed with
_are allowed - Prettier: single quotes, semicolons, 80 char width, trailing commas (es5)
ZEROEVAL_API_KEY— API authentication (auto-initializes SDK if set)ZEROEVAL_API_URL— Backend URL (default: https://api.zeroeval.com)ZEROEVAL_DEBUG— Enable debug logging