Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pypi

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

The interactions and embed_content methods are newly instrumented and may contain issues. Please treat the telemetry produced by these methods as experimental.

The interactions API currently does not support automatic function calling, so no execute_tool spans are generated.

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 for generate_content, 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_tokens
  • OTEL_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

Release files for opentelemetry-instrumentation-google-genai 1.1b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opentelemetry-instrumentation-google-genai 1.1b1
File Size Uploaded
opentelemetry_instrumentation_google_genai-1.1b1.tar.gz 107.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opentelemetry-instrumentation-google-genai 1.1b1
File Interpreter ABI Platform
opentelemetry_instrumentation_google_genai-1.1b1-py3-none-any.whl Python 3 none any Details

Total release size: 137.2 kB

Release files / opentelemetry_instrumentation_google_genai-1.1b1.tar.gz

Download URL opentelemetry_instrumentation_google_genai-1.1b1.tar.gz
Size 107.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c670f7f263d59b2d45ec1ee1e9126b7e3e67f2946fa89af89c6cc3041c778b13
BLAKE2b-256 checksum
How to use checksums
6ebffd8983789e4c689f5ac8a8f48ebdbc85b5e9babffa10fc3b58f5c65d9c9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release files / opentelemetry_instrumentation_google_genai-1.1b1-py3-none-any.whl

Download URL opentelemetry_instrumentation_google_genai-1.1b1-py3-none-any.whl
Size 29.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff66bf0c55adce849d635ac45a8420583528a3f9b49dac5569c2d100ab58d0e7
BLAKE2b-256 checksum
How to use checksums
c6a424bfbdb862a83a551e845ba516d38ecaba2cdc3e5457d5e55f1c2819431a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page