Skip to main content
LangWatch provides native instrumentation for the official Ollama Go client (github.com/ollama/ollama/api), covering its native /api/chat, /api/generate and /api/embed endpoints. It captures the model parameters, token counts (prompt_eval_count / eval_count), server-side phase durations, and tool calls, with NDJSON streaming reconstruction.
This page covers Ollama’s native API. If you talk to Ollama through an OpenAI client instead (the /v1/* compatibility shim), use the OpenAI instrumentation with option.WithBaseURL("http://localhost:11434/v1") and otelopenai.WithGenAIProvider(semconv.GenAIProviderNameKey.String("ollama")).

Installation

Usage

Set the LANGWATCH_API_KEY environment variable before running. Ollama runs locally, so no API key is needed for the model (the SDK reads OLLAMA_HOST, default http://localhost:11434).
NewHTTPClient returns a ready *http.Client to pass to api.NewClient. Register your LangWatch tracer provider first:
If you’d rather build the *http.Client yourself, use ollama.NewTransport() (or WrapHTTPClient(client, opts...) to preserve an existing client’s settings). The instrumentation captures input and output by default; pass ollama.WithDataCapture(langwatch.DataCaptureNone) to opt out.
The defer tp.Shutdown(ctx) call is essential. Without it, traces buffered in memory will be lost when your application exits.

Check it worked

Run the program with go run .. The deferred tp.Shutdown(ctx) flushes the spans when main returns. Then open your project in LangWatch: a new trace appears in the traces list within a few seconds, with the Ollama call as an LLM span carrying its input and output. If no trace appears, check that LANGWATCH_API_KEY is set in the environment the program runs in.
Last modified on October 29, 2026