google-genai SDK.
Setup
Usage
Once initialized, all Gemini calls are captured automatically — including tool-call requests:What Gets Captured
Run the example
Clone the repo and run a complete agent end-to-end.Python
Run the Python example
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
Auto-instrument Google Gemini API calls via the GenAI SDK
google-genai SDK.
import traceroot
from traceroot import Integration
traceroot.initialize(integrations=[Integration.GOOGLE_GENAI])
import os
from google import genai
from google.genai import types
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
weather_tool = types.Tool(function_declarations=[
types.FunctionDeclaration(
name="get_weather",
description="Get current weather for a city",
parameters=types.Schema(
type="OBJECT",
properties={"city": types.Schema(type="STRING", description="City name")},
required=["city"],
),
)
])
# This call is automatically traced
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="What's the weather in Tokyo?",
config=types.GenerateContentConfig(tools=[weather_tool]),
)
# The model asks to call get_weather; run it and send the result back yourself
print(response.function_calls)
tools, the SDK’s automatic function calling runs the whole tool loop inside one generate_content call. That records one span, priced on the last model call only. For accurate cost, pass function declarations instead (as above) or set automatic_function_calling=types.AutomaticFunctionCallingConfig(disable=True), and run the tool loop yourself as the example does.| Attribute | Description |
|---|---|
| Model | gemini-3.8-flash, gemini-3.5-flash-lite, gemini-3.1-pro-preview, etc. |
| Contents | Input messages |
| Response | Generated text and function calls |
| Tokens | Input and output token counts |
| Cost | Calculated from token usage and model pricing |
| Latency | Request duration |