OpenTelemetry instrumentation for Google Gen AI
Actively maintained. Last release 12 days ago, commits in 16 of the last 26 weeks. A safe choice.
pip install traceai-google-genaiREADME as published on PyPI with version 0.1.5.
Google Gen AI OpenTelemetry Integration
Overview
This integration provides support for using OpenTelemetry with the Google Gen AI framework. It enables tracing and monitoring of applications built with Google Gen AI.
Installation
- Install traceAI Google Gen AI
pip install traceAI-google-genai
Supported SDK: google-genai>=1.8.0; offline sync/async streaming trace tests verified on 1.8.0, 1.24.0, and 3.0.0.
Set Environment Variables
Set up your environment variables to authenticate with FutureAGI
import os
os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY
Quickstart
Register Tracer Provider
Set up the trace provider to establish the observability pipeline. The trace provider:
from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
trace_provider = register(
project_type=ProjectType.OBSERVE,
project_name="google_genai_project"
)
Configure Google Gen AI Instrumentation
Instrument the Google Gen AI client to enable telemetry collection. This step ensures that all interactions with the Google Gen AI SDK are tracked and monitored.
from traceai_google_genai import GoogleGenAIInstrumentor
GoogleGenAIInstrumentor().instrument(tracer_provider=trace_provider)
Make a request
Set up your Google Gen AI client with built-in observability.
from google import genai
from google.genai import types
client = genai.Client(vertexai=True, project="your_project_name", location="global")
content = types.Content(
role="user",
parts=[
types.Part.from_text(text="Hello how are you?"),
],
)
response = client.models.generate_content(
model="gemini-2.0-flash-001", contents=content
)
print(response)
Streaming output
For synchronous and asynchronous generate_content_stream calls, the exported
output.value preserves each candidate's parts in arrival order. Parallel tool
calls, repeated calls to the same function, and media parts remain distinct.
Text chunks are still concatenated in the message-content span attribute.
The response chunks delivered to your application are unchanged.