Guides
Tracing and running from TypeScript
The TypeScript SDK traces a Node application into Oloproof and runs a suite through the engine, with the same span names, attributes and endpoint as the Python SDK. A trace sent from Node is read by oloproof collect and oloproof traces list exactly as one sent from Python, and a run started from Node is the engine's run: the SDK parses the events the engine prints and computes no number of its own.
Install
npm install @oloproof/sdk
pip install 'oloproof[collect]'The SDK needs Node 22.12 or later and has no runtime dependency. The second line is the engine, which receives the traces and decides the runs (Python 3.11 or later). To score a system inside your own test runner and hand the scores to the engine, see Evaluating from Node; this page covers tracing and runs.
Trace a function
Start the local collector in your project:
oloproof collectThen wrap the functions you want to see. trace wraps a function, sync or async; withSpan records one step inside it:
import { tracing, trace, withSpan } from "@oloproof/sdk";
tracing.init();
const answer = trace("answer", async (question: string) => {
const passages = await withSpan("retrieve", async (step) => {
const found = await search(question);
step.output(found);
return found;
}, { kind: "retriever", input: question });
return generate(question, passages);
});Spans nest as the calls nest, across await, so concurrent requests keep separate traces. A traced function's argument is its span's input (several arguments are recorded as { "args": [...] }) and its return value, or what its promise resolves to, the output. An exception marks the span failed, records it as an exception event, and is thrown again. step.set(key, value) adds an attribute of your own.
The span kinds are chain (the default), tool, retriever, llm and agent, written as OpenInference's openinference.span.kind; input and output are input.value and output.value. Content is recorded as JSON and cut at 20,000 characters (maxChars); tracing.init({ capture: false }) keeps the structure, models and tokens and leaves content out.
Trace model calls
instrumentOpenAI and instrumentAnthropic wrap a client of the official openai or @anthropic-ai/sdk package, in place:
import OpenAI from "openai";
import { instrumentOpenAI } from "@oloproof/sdk";
const client = instrumentOpenAI(new OpenAI());Every client.chat.completions.create (or, for Anthropic, client.messages.create) becomes a span named openai.chat or anthropic.chat, nested under the open span, with OpenTelemetry's GenAI attributes: gen_ai.system, gen_ai.request.model, gen_ai.response.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, and the messages in gen_ai.input.messages and gen_ai.output.messages. The call returns the client's own promise, unchanged. Neither package is a dependency of the SDK.
A streamed call (stream: true) records its request, model and input messages, and not the streamed reply or its tokens, which arrive after the call returns. The Python SDK has the same limit.
Trace LangChain.js and OpenAI Agents
Two framework integrations come from @oloproof/sdk/tracing, the Node twins of the Python SDK's oloproof.integrations.langchain and oloproof.integrations.openai_agents. Neither framework is a dependency of the SDK: both are typed by the methods and fields they read.
OloproofCallbackHandler is a LangChain.js callback handler:
import { OloproofCallbackHandler } from "@oloproof/sdk/tracing";
await chain.invoke(inputs, { callbacks: [new OloproofCallbackHandler()] });Every chain (and LangGraph.js node), model, tool and retriever run becomes a span, nested as LangChain nests them, with the kinds CHAIN, LLM, TOOL and RETRIEVER. A model span carries gen_ai.operation.name, gen_ai.response.model and the token counts (gen_ai.usage.input_tokens, gen_ai.usage.output_tokens) from the result's llmOutput or the message's usage_metadata; a tool span carries tool.name; a retriever span carries each document's content and id as retrieval.documents.N.document.content and .id. A run whose parent the handler did not see nests under the open trace or withSpan, if there is one.
OloproofTraceProcessor is a tracing processor for OpenAI Agents JS (@openai/agents):
import { addTraceProcessor } from "@openai/agents";
import { OloproofTraceProcessor } from "@oloproof/sdk/tracing";
addTraceProcessor(new OloproofTraceProcessor());The Agents SDK traces its own runs; the processor turns each run into an AGENT span and each of its spans into a child: agent spans (with gen_ai.agent.name), function spans as TOOL (with tool.name), generation and response spans as LLM with the model and tokens, and handoff, guardrail and custom spans as CHAIN. A span the SDK marks with an error is recorded as failed. Content follows capture and maxChars as for every other span.
Where spans go
Spans are batched and posted as OTLP/HTTP JSON to OLOPROOF_TRACE_ENDPOINT, or to oloproof collect on this machine (http://127.0.0.1:4318/v1/traces) when it is not set; tracing.init({ endpoint }) names another. A hosted workspace's endpoint takes its token in headers, or in OTEL_EXPORTER_OTLP_HEADERS as the OpenTelemetry exporters read it. Any other OpenTelemetry backend can receive the same spans.
A batch is sent every five seconds, at 512 spans, and when the process is about to exit. A script that ends with process.exit, or a serverless handler, calls await tracing.shutdown() (or tracing.flush()) first. Then list what arrived:
oloproof traces listRun a suite
run starts oloproof run --json in your project, reads its event stream, and resolves when the engine exits:
import { run } from "@oloproof/sdk";
const result = await run({ cwd: "path/to/project", onEvent: (event) => console.log(event.type) });
console.log(result.runId, result.exitCode, result.verdict?.release_action);result.exitCode is the engine's exit code, unchanged, and result.exit its name (OK, FAIL, INSUFFICIENT_EVIDENCE and so on). When a policy decides the run, result.verdict is the gate's verdict from the run_decided event, with each rule's state, estimate and range as the engine wrote them; a run with no bar has result.explored instead, with the engine's plain words and nothing decided. If the engine stops on an error, result.error is its error document. config and policy are passed as --config and --policy. Every event type is listed in Progress and concurrency.
gate(runId) runs oloproof gate RUN --json on a stored run and returns its verdict and exit code the same way. If oloproof is not on your PATH, both throw EngineNotFoundError; pass command with the path to the executable instead.