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.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 Gemini 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 - Instrumentation options and collected attributes
- Capturing Evaluations & Guardrails - Log evaluations and implement guardrails in your Google Gemini applications