Registry /
observability / opentelemetry-instrumentation-ollama
Install & Compatibility
Where this runs
tested against v0.62.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.464s · 73.4MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.9s · import 0.442s · 37MB
55MB installed
● package 55MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
OllamaInstrumentor
✓ from opentelemetry.instrumentation.ollama import OllamaInstrumentor
This quickstart demonstrates how to set up a basic OpenTelemetry `TracerProvider` that exports traces to the console, and then instruments the `ollama` client to automatically capture traces for chat and generate operations. Ensure you have the `ollama` client library installed and an Ollama server running locally with the `llama2` model pulled.
import os
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, BatchSpanProcessor
from opentelemetry.instrumentation.ollama import OllamaInstrumentor
import ollama
# 1. Set up OpenTelemetry Tracer Provider
# This simple setup exports traces to the console.
resource = Resource.create(attributes={"service.name": "ollama-app"})
provider = TracerProvider(resource=resource)
processor = BatchSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# 2. Instrument Ollama
OllamaInstrumentor().instrument()
# 3. Use Ollama client (ensure ollama server is running and model pulled)
try:
print("\n--- Making an Ollama chat request ---")
chat_response = ollama.chat(
model='llama2',
messages=[{'role': 'user', 'content': 'Why is the sky blue?'}]
)
print("Ollama Chat Response:")
print(chat_response['message']['content'])
print("\n--- Trace for chat request should be visible above ---")
print("\n--- Making an Ollama generate request (streaming) ---")
stream = ollama.generate(
model='llama2',
prompt='Tell me a short story about a space-faring cat.',
stream=True
)
full_response = ""
print("Streaming Ollama Response:")
for chunk in stream:
if 'response' in chunk:
full_response += chunk['response']
print(chunk['response'], end='', flush=True)
print("\n\n--- Trace for streaming request should be visible above ---")
except Exception as e:
print(f"\nError interacting with Ollama: {e}")
print("Please ensure the Ollama server is running (e.g., `ollama serve`) ")
print("and the 'llama2' model is pulled (e.g., `ollama pull llama2`).")
Upgrade
Version history
0.62.3latest on PyPI · released Aug 10, 2026
Audit
Dependencies
ollamarequiredThe instrumentation traces calls made using the official Ollama Python client library. This package is not a direct dependency of the instrumentation itself but is required for its functionality.
opentelemetry-apirequiredCore OpenTelemetry API for defining telemetry. Implicit dependency for any OpenTelemetry instrumentation.
opentelemetry-sdkrequiredCore OpenTelemetry SDK for processing and exporting telemetry. Implicit dependency for any OpenTelemetry instrumentation.
opentelemetry-distrooptionalProvides default OpenTelemetry API/SDK setup and helpful auto-instrumentation tools (like `opentelemetry-bootstrap` and `opentelemetry-instrument`) for easier setup.