Skip to main content
LangWatch provides native instrumentation for Google’s unified Gen AI Go SDK (google.golang.org/genai), which covers both the Gemini Developer API and Vertex AI behind one client. It traces at the HTTP layer the genai client uses, recording request and response attributes, including all token kinds Gemini reports (prompt, candidates, cached content, and thoughts as reasoning tokens), with full streaming support.

Installation

Usage

Set LANGWATCH_API_KEY and GEMINI_API_KEY environment variables before running.
WrapClientConfig sets the client’s HTTP transport to a traced one in place, preserving any transport you already configured. Register your LangWatch tracer provider first, then wrap the genai.ClientConfig:
For the Vertex AI backend set Backend: genai.BackendVertexAI. If you build the *http.Client yourself, use googlegenai.NewTransport() (or NewTransportWithBase(base, opts...) to chain an authenticated transport for Vertex). The instrumentation captures input and output by default; pass googlegenai.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.
Last modified on September 8, 2026