Google (Gemini & Vertex)

google-genai and vertexai auto-capture generate_content and streaming variants.

Two instrumentors, one per SDK: one for the Gemini API (the new google-genai SDK) and one for Vertex AI (vertexai). Calls inside wrap your agent become llm spans. The provider field is google for Gemini and google-vertex for Vertex.

What's captured

CallSpan kindAuto-extracted
client.models.generate_contentllmmodel, tokens (usage_metadata), prompt, response
client.models.generate_content_streamllmsame, accumulated across chunks
client.chats.create then send_messagellmsame, with chat history in input
Vertex GenerativeModel.generate_contentllmmodel, tokens, prompt, response

Install

# Gemini API — the instrumentor patches the NEW google-genai SDK
pip install google-genai opentelemetry-instrumentation-google-generativeai

# Vertex AI
pip install google-cloud-aiplatform opentelemetry-instrumentation-vertexai

Current opentelemetry-instrumentation-google-generativeai releases import google.genai and only patch the new google-genai SDK — the deprecated google-generativeai package is no longer instrumented. If your code still uses import google.generativeai, migrate to from google import genai.

For Node, install @traceloop/instrumentation-google-generativeai — trodo resolves it automatically:

npm install @google/genai@^1 @traceloop/instrumentation-google-generativeai

The Node instrumentor currently patches @google/genai v1.x only (>=1.0.0 <2.0.0). On @google/genai@2.x it silently skips — your calls succeed but no llm spans are captured. Pin @google/genai@^1 until the instrumentor adds 2.x support.

Minimal example — Gemini

import os, trodo
from google import genai

trodo.init(site_id=os.environ['TRODO_SITE_ID'])
client = genai.Client(api_key=os.environ['GEMINI_API_KEY'])

with trodo.wrap_agent('gemini-bot') as run:
    r = client.models.generate_content(
        model='gemini-2.5-flash',
        contents='Explain vector databases in one sentence.',
    )
    run.set_output(r.text)

Streaming (client.models.generate_content_stream) is captured the same way, with tokens accumulated across chunks.

Minimal example — Vertex

import os, trodo, vertexai
from vertexai.generative_models import GenerativeModel

trodo.init(site_id=os.environ['TRODO_SITE_ID'])
vertexai.init(project=os.environ['GCP_PROJECT'], location='us-central1')
model = GenerativeModel('gemini-2.5-pro')

with trodo.wrap_agent('vertex-bot') as run:
    r = model.generate_content('Explain vector databases in one sentence.')
    run.set_output(r.text)

Tokens come from usage_metadata: prompt_token_count maps to input tokens and candidates_token_count to output tokens.

On this page