This release is a pre-release and may not be stable for production use.
OpenTelemetry Google GenAI SDK Instrumentation
This library adds instrumentation to the Google GenAI SDK library to emit telemetry data following Semantic Conventions for GenAI systems. It adds trace spans for GenAI operations, events/logs for recording prompts/responses, and emits metrics that describe the GenAI operations in aggregate.
Experimental
This package is still experimental. The instrumentation may not be complete or correct just yet.
Please see “TODOS.md” for a list of known defects/TODOs that are blockers to package stability.
Installation
If your application is already instrumented with OpenTelemetry, add this package to your requirements.
pip install opentelemetry-instrumentation-google-genai
If you don’t have a Google GenAI SDK application, yet, try our examples.
Check out zero-code example for a quick start.
Usage
This section describes how to set up Google GenAI SDK instrumentation if you’re setting OpenTelemetry up manually. Check out the manual example for more details.
Instrumenting all clients
When using the instrumentor, all clients will automatically trace GenAI generate_content operations. You can also optionally capture prompts and responses as log events.
Make sure to configure OpenTelemetry tracing, logging, metrics, and events to capture all telemetry emitted by the instrumentation.
from opentelemetry.instrumentation.google_genai import GoogleGenAiSdkInstrumentor
from google.genai import Client
GoogleGenAiSdkInstrumentor().instrument()
client = Client()
response = client.models.generate_content(
model="gemini-1.5-flash-002",
contents="Write a short poem on OpenTelemetry."
)
Limitations
When using the Google GenAI SDK with automatic function calling enabled, the OpenTelemetry instrumentation creates a span only for the top-level generate_content call.
Internal model or tool calls triggered automatically by the SDK are executed within the SDK internals and are not traced as separate spans.
Enabling message content
Message content such as the contents of the prompt and response are not captured by default. To capture message content as log events, set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to true.
Uninstrument
To uninstrument clients, call the uninstrument method:
from opentelemetry.instrumentation.google_genai import GoogleGenAiSdkInstrumentor
GoogleGenAiSdkInstrumentor().instrument()
# ...
# Uninstrument all clients
GoogleGenAiSdkInstrumentor().uninstrument()
References
Metadata
Release files for opentelemetry-instrumentation-google-genai 0.7b2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| opentelemetry_instrumentation_google_genai-0.7b2.tar.gz | 52.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opentelemetry_instrumentation_google_genai-0.7b2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 84.1 kB
Release files / opentelemetry_instrumentation_google_genai-0.7b2.tar.gz
| Download URL | opentelemetry_instrumentation_google_genai-0.7b2.tar.gz |
|---|---|
| Size | 52.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef185a2a0d431f73c95422b7781c68d2220fda35524e04561168adcdfb46b128
|
|
BLAKE2b-256 checksum How to use checksums |
20eb66cb9379aabd4878999694c94c35f2434890fb187808091c70cf310d8c28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / opentelemetry_instrumentation_google_genai-0.7b2-py3-none-any.whl
| Download URL | opentelemetry_instrumentation_google_genai-0.7b2-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fae012778741915261f558d72dd58a7bc3149a43beaa03e841824d727ab2a0f3
|
|
BLAKE2b-256 checksum How to use checksums |
38da548821b789167251750ff9f8dcc5ee5f77369baec310c0108bcf9aebbf05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for opentelemetry-instrumentation-google-genai 0.7b2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.