Registry /
observability / opentelemetry-instrumentation-google-generativeai
Install & Compatibility
Where this runs
tested against v0.62.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 202.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 10.9s · import 0.000s · 200MB
202MB installed
● package 202MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GoogleGenerativeAIInstrumentor
✓ from opentelemetry.instrumentation.google_generativeai import GoogleGenerativeAIInstrumentor
✗ from opentelemetry.instrumentation.google_generative_ai import GoogleGenerativeAIInstrumentor
Note the underscore vs. hyphen in the package name and the module path.
This quickstart demonstrates how to set up the OpenTelemetry SDK with a console exporter, initialize the `GoogleGenerativeAIInstrumentor`, and then make a request using the `google-generativeai` client. Traces for the `generate_content` call will be printed to the console.
import os
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.instrumentation.google_generativeai import GoogleGenerativeAIInstrumentor
import google.generativeai as genai
# Configure OpenTelemetry SDK for console output
resource = Resource.create({"service.name": "google-generativeai-example"})
provider = TracerProvider(resource=resource)
processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# Initialize the Google Generative AI instrumentation
GoogleGenerativeAIInstrumentor().instrument()
# Configure Google Generative AI with API key
genai.configure(api_key=os.environ.get("GOOGLE_API_KEY", ""))
# Make a call to the Generative AI model
if genai.get_default_base_url(): # Check if API key might be configured
try:
model = genai.GenerativeModel('gemini-pro')
print("Calling Gemini-Pro...")
response = model.generate_content("What is OpenTelemetry?", stream=False)
print(f"Response: {response.text[:100]}...")
except Exception as e:
print(f"Error calling Google Generative AI: {e}")
print("Ensure GOOGLE_API_KEY environment variable is set.")
else:
print("Google Generative AI API key not configured. Set GOOGLE_API_KEY environment variable.")
Debug
Known issues
breakingThe OpenTelemetry Generative AI Semantic Conventions are actively evolving. This instrumentation frequently updates to conform to new versions of these conventions, which can result in changes to span names, attribute keys, and attribute values between minor versions. If you rely on specific trace data for analysis or alerting, you may need to update your configurations.fixReview the release notes for changes related to 'GenAI semantic conventions'. Update your OpenTelemetry collector processors, analysis dashboards, or alerting rules to match the latest attribute names and values. Consider pinning to specific minor versions if stability is critical.
affects: 0.53.0 and newer (e.g., 0.53.4, 0.54.0, 0.55.0, 0.58.0)
gotchaThis package only provides the instrumentation. To actually see traces, you must install and configure the `opentelemetry-sdk` with a `TracerProvider`, `SpanProcessor`, and an `Exporter` (e.g., `ConsoleSpanExporter`, `OTLPSpanExporter`). Without this setup, instrumentation will run but no traces will be emitted.fixEnsure your application code includes the full OpenTelemetry SDK setup as shown in the quickstart example, or that it is handled by an OpenTelemetry auto-instrumentation agent if applicable.
affects: All versions
gotchaThe `google-generativeai` library itself is a required peer dependency. This instrumentation package does not install it automatically.fixAlways install `google-generativeai` alongside `opentelemetry-instrumentation-google-generativeai` using `pip install opentelemetry-instrumentation-google-generativeai google-generativeai`.
affects: All versions
gotchaThe Google Generative AI client requires an API key, which must be configured either via the `GOOGLE_API_KEY` environment variable or explicitly through `genai.configure(api_key='YOUR_API_KEY')`.fixSet the `GOOGLE_API_KEY` environment variable or ensure `genai.configure(api_key=...)` is called before making model requests.
affects: All versions
Upgrade
Version history
0.62.3latest on PyPI · released Aug 10, 2026
Audit
Dependencies
google-generativeairequiredThis is the core library being instrumented; it must be installed for the instrumentation to function.
opentelemetry-apirequiredProvides the OpenTelemetry API for creating traces.
opentelemetry-sdkrequiredRequired for a full OpenTelemetry setup, including `TracerProvider`, `SpanProcessor`, and `Exporter`, to make traces visible.