openai-go/v3 client library through a dedicated middleware that captures detailed information about your OpenAI API calls. It handles Chat Completions, the Responses API and Embeddings, with full streaming support.
Installation
Usage
Set
LANGWATCH_API_KEY and OPENAI_API_KEY environment variables before running.The middleware captures input and output content by default (
langwatch.DataCaptureAll). To opt out, pass otelopenai.WithDataCapture(langwatch.DataCaptureNone) (or DataCaptureInput / DataCaptureOutput to capture only one side).Check it worked
Run the program withgo 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 OpenAI call as an LLM span carrying its input, output and token counts.
If no trace appears, check that LANGWATCH_API_KEY is set in the environment the program runs in.
Related
- Go Integration Guide - Setup, manual spans, data capture and the REST client
- Go SDK API Reference - Middleware options and collected attributes
- Capturing Evaluations & Guardrails - Log evaluations and implement guardrails