Skip to content

Trace Helpers

Trace helpers read a harness run. First-party harnesses attach native spans when provider/runtime data exposes real operations. Custom harnesses created with createHarness() get a fallback run span unless they return their own traces.

Use trace helpers for operational behavior that is not represented by output, messages, or tool calls.

evals/refund.eval.ts
import { expect } from "vitest";
import {
failedSpans,
spansByKind,
} from "vitest-evals";
expect(spansByKind(result, "model").length).toBeGreaterThan(0);
expect(failedSpans(result)).toHaveLength(0);

Use spans(result) when you need the full flattened span list. The helpers also accept a normalized trace array when that is the only value available.

evals/refund.eval.ts
import { spans } from "vitest-evals";
expect(spans(result).some((span) => span.status === "error")).toBe(false);
HelperUse
spansFlatten every span from a run.
spansByKindFilter spans by run, model, tool, or another span kind.
failedSpansRead spans with error status or normalized errors.