This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 1.0b1 instead.
Reason given by maintainers: Breaks imports due to loose dependency version bounds
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, embed_content and interactions.create operations. You can also optionally capture prompts and responses as log events.
Make sure to configure OpenTelemetry tracing, logging, and metrics 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 an execute_tool span for each tool call the SDK executes, these spans are nested under the generate_content span.
Only tool calls that the SDK executes are traced, if you disable the automatic function calling and instead do the function calling in your application, our instrumentation cannot trace them.
Enabling message content
Message content is not captured by default. To capture message content set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to one of NO_CONTENT, SPAN_AND_EVENT, SPAN_ONLY, EVENT_ONLY. This controls whether the following content is captured on spans and/or events:
Input messages to the LLM.
Output messages from the LLM.
System Instructions
The result of tool calls and the tool call parameters (other tool call details and tool definitions are always captured).
Configuration recording
The instrumentation can optionally record GenerateContentConfig parameters as span and event attributes under the gcp.gen_ai.operation.config.* namespace.
By default, no config fields are recorded. You can control which fields are captured using the following environment variables:
OTEL_GOOGLE_GENAI_GENERATE_CONTENT_CONFIG_INCLUDES — A comma-separated list of config field names to include in the span attributes. For example:
export OTEL_GOOGLE_GENAI_GENERATE_CONTENT_CONFIG_INCLUDES=temperature,max_output_tokensOTEL_GOOGLE_GENAI_GENERATE_CONTENT_CONFIG_EXCLUDES — A comma-separated list of config field names to exclude from the span attributes:
export OTEL_GOOGLE_GENAI_GENERATE_CONTENT_CONFIG_EXCLUDES=stop_sequences
If both variables are set, the includes list is applied first, then the excludes list filters the result further.
Uninstrument
To uninstrument clients, call the uninstrument method:
from opentelemetry.instrumentation.google_genai import GoogleGenAiSdkInstrumentor
GoogleGenAiSdkInstrumentor().instrument()
# ...
# Uninstrument all clients
GoogleGenAiSdkInstrumentor().uninstrument()
References
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentelemetry_instrumentation_google_genai-1.0b0.tar.gz.
File metadata
- Download URL: opentelemetry_instrumentation_google_genai-1.0b0.tar.gz
- Upload date:
- Size: 75.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e89118fe44ea89b006e851a7b1d6a59f53071624c0b6a24c925e0f03ebd55c3
|
|
| MD5 |
75e7ad3d8ec5dfc1e314818bd057f917
|
|
| BLAKE2b-256 |
653bf1b77ede91dc424fc63d029611f08a2acb9e6c9c168e4454af0a4c7147b3
|
Provenance
The following attestation bundles were made for opentelemetry_instrumentation_google_genai-1.0b0.tar.gz:
Publisher:
release-all.yml on open-telemetry/opentelemetry-python-genai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_google_genai-1.0b0.tar.gz -
Subject digest:
0e89118fe44ea89b006e851a7b1d6a59f53071624c0b6a24c925e0f03ebd55c3 - Sigstore transparency entry: 2132312159
- Sigstore integration time:
-
Permalink:
open-telemetry/opentelemetry-python-genai@1e4aca50a0c5b5fcf8b3e2a7a81eec6ac12a1669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-telemetry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-all.yml@1e4aca50a0c5b5fcf8b3e2a7a81eec6ac12a1669 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file opentelemetry_instrumentation_google_genai-1.0b0-py3-none-any.whl.
File metadata
- Download URL: opentelemetry_instrumentation_google_genai-1.0b0-py3-none-any.whl
- Upload date:
- Size: 26.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a233eb8d0d301e6dac5d245c9f7b02bf659b7462fbee2e5b429711a480f9bd9
|
|
| MD5 |
4efc758aa69461c04b294d713c6b52ea
|
|
| BLAKE2b-256 |
fe6af45fc4a89a2ab9b1b4fc1ecae9c46b3e465c1a556e926e2f1e6ca370fccc
|
Provenance
The following attestation bundles were made for opentelemetry_instrumentation_google_genai-1.0b0-py3-none-any.whl:
Publisher:
release-all.yml on open-telemetry/opentelemetry-python-genai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opentelemetry_instrumentation_google_genai-1.0b0-py3-none-any.whl -
Subject digest:
0a233eb8d0d301e6dac5d245c9f7b02bf659b7462fbee2e5b429711a480f9bd9 - Sigstore transparency entry: 2132312278
- Sigstore integration time:
-
Permalink:
open-telemetry/opentelemetry-python-genai@1e4aca50a0c5b5fcf8b3e2a7a81eec6ac12a1669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-telemetry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-all.yml@1e4aca50a0c5b5fcf8b3e2a7a81eec6ac12a1669 -
Trigger Event:
workflow_dispatch
-
Statement type: