Skip to main content

OpenInference Ollama Instrumentation

pypi

Python auto-instrumentation library for the Ollama Python client.

The traces emitted by this instrumentation are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as Arize Phoenix or Arize AX.

What is instrumented

chat calls made through ollama.chat, ollama.Client.chat, and ollama.AsyncClient.chat are exported as OpenInference LLM spans (named Chat and AsyncChat respectively), capturing:

  • Input and output messages (llm.input_messages.*, llm.output_messages.*), including tool calls
  • Streaming (stream=True): the span finishes when the stream is exhausted, fails, or is abandoned, with the output message and token counts reconstructed from the accumulated chunks
  • Tool definitions as llm.tools.N.tool.json_schema — plain Python functions passed via tools=[...] are converted to their JSON schemas
  • llm.provider (ollama) and llm.model_name (recorded from the request as well, so errored calls still carry the model)
  • Token counts: prompt_eval_count → llm.token_count.prompt, eval_count → llm.token_count.completion, with the total derived when both are present
  • llm.invocation_parameters (request options other than messages, model, and tools)
  • Errors: exceptions set the span status to ERROR and are recorded as span events

Not currently instrumented: generate, embed/embeddings, and other client methods.

Context attributes (session, user, metadata, tags via using_attributes) propagate onto spans, and sensitive data can be masked with a TraceConfig, e.g. OllamaInstrumentor().instrument(tracer_provider=tracer_provider, config=TraceConfig(hide_inputs=True)). Calls made inside with suppress_tracing(): are not traced.

Installation

pip install openinference-instrumentation-ollama

PyPI package: openinference-instrumentation-ollama

Requires ollama >= 0.4.0.

Quickstart

Install packages needed for this demonstration.

pip install openinference-instrumentation-ollama ollama arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp

Install and start the Ollama server (pip install ollama installs only the client), then pull a model. The server listens on http://localhost:11434 by default.

ollama pull llama3.2

Start Phoenix in the background as a collector. By default, it listens on http://localhost:6006. (Phoenix does not send data over the internet. It only operates locally on your machine.)

phoenix serve

Set up OllamaInstrumentor to trace your application and send the traces to Phoenix.

from openinference.instrumentation.ollama import OllamaInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))

OllamaInstrumentor().instrument(tracer_provider=tracer_provider)

Run a chat completion against the locally running Ollama server.

import ollama

response = ollama.chat(
    model="llama3.2",
    messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(response.message.content)

Now view your traces in the Phoenix UI at http://localhost:6006.

Examples

The examples/ directory contains runnable scripts. They require a running Phoenix and Ollama server, read the model from the OLLAMA_MODEL environment variable (default llama3.2), and send traces to a Phoenix project named ollama-examples.

pip install -r examples/requirements.txt
OLLAMA_MODEL=llama3.2 python examples/chat.py
Example Description
chat.py A basic chat completion
streaming_and_tools.py Streaming with session attributes, and tool calling with a plain Python function

Development

From the python/ directory: tox run -e test-ollama runs the tests, and tox run -e ruff-mypy-test-ollama runs all checks.

More Info

Metadata

Release files for openinference-instrumentation-ollama 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openinference-instrumentation-ollama 0.1.13
File Size Uploaded Provenance
openinference_instrumentation_ollama-0.1.13.tar.gz 14.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for openinference-instrumentation-ollama 0.1.13
File Interpreter ABI Platform
openinference_instrumentation_ollama-0.1.13-py3-none-any.whl Python 3 none any Details

Total release size: 34.5 kB

Release files / openinference_instrumentation_ollama-0.1.13.tar.gz

Download URL openinference_instrumentation_ollama-0.1.13.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9e88870acb5b63d2f0e782f5579e2d662952e196cfb3bedd106767a67e2b7eee
BLAKE2b-256 checksum
How to use checksums
e9641607f3d8b7eec85f022c484c667aa9c611e28c58478e304d45afbb87ec6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / openinference_instrumentation_ollama-0.1.13-py3-none-any.whl

Download URL openinference_instrumentation_ollama-0.1.13-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3557d242fc66476f0463134ec8dc8adc55301d4de04f6e2db4963c5b8f08b916
BLAKE2b-256 checksum
How to use checksums
235349e63e206eda7b07b3ce4d21be0306d23c9a27adae2815e0ebab28dac582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for openinference-instrumentation-ollama 0.1.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for openinference_instrumentation_ollama-0.1.13.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page