Skip to main content
Ollama lets you run open-weight large language models locally and call them through a simple Python client. The Ollama Python client can be instrumented using the openinference-instrumentation-ollama package.

Coverage

The instrumentor traces chat calls made through ollama.chat, ollama.Client.chat, and ollama.AsyncClient.chat, including streaming responses (stream=True) and tool calls. It captures input and output messages, token counts, the model name (also on error spans), and invocation parameters. When plain Python functions are passed as tools, their schemas are captured under llm.tools.N.tool.json_schema. Other client methods — including generate and embed/embeddings — are not currently traced.

Install

Setup

Make sure a local Ollama server is running and the model you want to use has been pulled, for example ollama pull llama3.2. Connect your application to Phoenix and instrument the Ollama client:
Instrument the client before you import or call it. Aliases captured before instrumentation are not traced — for example, from ollama import chat binds the unwrapped method at import time, so calls to that alias will not produce spans. Instrument first, or call ollama.chat(...) via the module attribute.

Run Ollama

For streaming, async (AsyncClient.chat), and tool-call examples, see the example scripts in the OpenInference package.

Observe

Now that you have tracing setup, all chat calls made through your Ollama application will be streamed to your running Phoenix for observability and evaluation.

Resources