Ollama
Trace models served by Ollama with cetra from Python, with the OpenInference Ollama instrumentation.
Install
Section titled “Install”pip install "cetra-sdk[ollama]" ollamaSet up
Section titled “Set up”import ollama
import cetra
cetra.init(instrument=["ollama"])
response = ollama.chat( model="llama3.1", messages=[{"role": "user", "content": "What is the capital of France?"}],)print(response.message.content)
cetra.flush()What you get
Section titled “What you get”- Each chat call is an
llmspan with the providerollama. - Input and output token counts come from the response.
- Cost comes from the built-in prices.
Limits
Section titled “Limits”- Only non-streaming chat is captured.
- Through the OpenAI client on
localhost, the provider staysopenai: cetra cannot tell a local server from another. - Common Ollama models are in the built-in prices at 0; add a custom model price for others.
- The fixtures were captured with ollama 0.6.3 and openinference-instrumentation-ollama 0.1.20.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Custom model prices: price a model the built-in prices do not cover.