ollama npm package.
Setup
Install Braintrust alongside the Ollama client..env
Auto-instrumentation
To trace Ollama without modifying your application code, run your app with Braintrust’s import hook. The hook patches theollama client at runtime.1
Initialize Braintrust and call Ollama
2
Run with the import hook
node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.If you’re using a bundler, see Trace LLM calls for plugin and loader setup.
Manual instrumentation
To trace Ollama manually, wrap the client yourself withwrapOllama().What Braintrust traces
Braintrust traces chat, generate, and embedding calls from theollama client:- Chat spans (
ollama.chat), with messages and request parameters as input and the response message as output. Tool calls are normalized to the OpenAI function-call format. - Generate spans (
ollama.generate), with the prompt (plus optional system prompt and images) as input and the generated text as output. Thinking content is captured asreasoning. - Embedding spans (
ollama.embed), with the input text as input and the first embedding’s vector length as output. - Token usage metrics (
prompt_tokensandcompletion_tokens) from Ollama’sprompt_eval_countandeval_countresponse fields. - Model name and request options (temperature, top_p, max_tokens, and others) as span metadata.
- Image inputs are captured as attachments.
- Errors captured on every span.