Google Gemini
Wrap the Google GenAI SDK in TypeScript or Python. Gemini generations, chats, streams, and embeddings traced with tokens, safety metadata, and cost.
Built by
telemetry.dev
Language
TypeScript + Python
Packages
@telemetry-dev/google-genai · telemetry-dev-google-genai
Category
Model providers
About the Google Gemini integration
@telemetry-dev/google-genai (TypeScript) and telemetry-dev-google-genai (Python) wrap the official Google GenAI SDKs. generateContent, generateContentStream, chat sessions, and embedContent become spans with the full Gemini request mapped to OpenTelemetry GenAI attributes — system instructions, sampling params, tools, safety settings, thinking config, and cached content. Provider is recorded as gcp.gemini for the Gemini Developer API and gcp.vertex_ai for Vertex clients.
Key features
- Deep attribute mapping: Finish reasons, usage, safety ratings, grounding metadata, and block reasons are all captured as queryable attributes.
- Streaming with TTFT: Streamed generations record time-to-first-chunk, merge text parts across chunks, and end the span exactly once — even on early exit or error.
- Chat sessions traced automatically:
chats.create(...).sendMessageroutes through the wrapped methods, so chats are covered whether created before or after wrapping. - Automatic function calling: An internal AFC loop produces one span covering the whole loop, with the AFC history as span input.
- Fail-open guarantee: Wrapped calls preserve original return values and errors; without telemetry initialized they behave exactly like the unwrapped SDK.
Get started
import { GoogleGenAI } from "@google/genai";
import { init } from "@telemetry-dev/sdk";
import { wrapGoogleGenAI } from "@telemetry-dev/google-genai";
init({ apiKey: process.env.TELEMETRY_DEV_API_KEY });
const ai = wrapGoogleGenAI(new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY! }));
await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "Say hello",
});
In Python, wrap_google_genai patches both sync client.models and async client.aio.models, and instrument_google_genai() is available for global instrumentation:
import telemetry_dev
from google import genai
from telemetry_dev_google_genai import wrap_google_genai
telemetry_dev.init()
client = wrap_google_genai(genai.Client(api_key="..."))
client.models.generate_content(
model="gemini-2.5-flash",
contents=[{"role": "user", "parts": [{"text": "Say hello"}]}],
)