OpenTelemetry Instrumentation for Google Generative AI

OpenTelemetry auto-instrumentation for Google Gemini and Generative AI calls in Python

Library
PyPI
v0.62.3
7,454 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
79 /100 Good
Development Activity 76
Maintenance 76
Community 72
Maturity 52
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 80
Code Quality 80
Innovation 76
Learning Curve 84

opentelemetry-instrumentation-google-generativeai is part of Traceloop’s OpenLLMetry suite and provides OpenTelemetry instrumentation for Google’s Generative AI (Gemini) Python library. Once enabled, it automatically traces prompts and completions, emitting spans and metrics that follow OpenTelemetry semantic conventions for LLM workloads, so Gemini usage shows up in any OTLP-compatible observability backend without manual span code.

Instrumentation is a single call, GoogleGenerativeAiInstrumentor().instrument(), after which model calls are wrapped transparently. It captures request and response content by default (which can be disabled for privacy), records token and latency metrics, and integrates with the broader OpenTelemetry Python ecosystem.

What You Get

  • One-line instrumentation of Google Gemini / Generative AI calls via GoogleGenerativeAiInstrumentor
  • Spans following OpenTelemetry GenAI semantic conventions for prompts and completions
  • Captured request/response content, configurable off for privacy via TRACELOOP_TRACE_CONTENT
  • Token usage and latency metrics emitted alongside traces
  • Registration as a standard OpenTelemetry instrumentor entry point for auto-loading

Common Use Cases

  • Observing and debugging Gemini-powered features in production
  • Measuring token consumption and latency of Google Generative AI calls
  • Feeding LLM traces into an existing OpenTelemetry/OTLP backend
  • Evaluating output quality by inspecting logged prompts and completions

Under The Hood

Architecture - The package lives under opentelemetry/instrumentation/google_generativeai/. __init__.py defines GoogleGenerativeAiInstrumentor (subclassing OpenTelemetry’s BaseInstrumentor), which patches the Gemini client’s generate-content methods; span_utils.py builds spans and sets GenAI attributes, event_emitter.py/event_handler.py/event_models.py handle the newer event-based semantic conventions, and config.py/utils.py cover content-capture toggles and helpers. It supports both sync and async call paths.

Tech Stack - Python 3.10+, built on opentelemetry-api, opentelemetry-instrumentation, and opentelemetry-semantic-conventions(-ai), with google-genai as an optional instruments extra. Packaged with a PEP 621 pyproject and managed in the OpenLLMetry monorepo via uv/poetry.

Code Quality - The package ships a real test suite (tests/) covering sync and async generation, finish reasons, metrics, and the new library instrumentation path, using pytest with VCR cassettes (pytest-recording) to replay real Gemini responses deterministically. Ruff is configured for linting.

API Design - Developer experience is excellent: a single instrument() call activates tracing with zero changes to model-call sites, privacy is one environment variable away, and it slots into standard OpenTelemetry auto-instrumentation through its instrumentor entry point, so it behaves like every other OTel instrumentation package.

Used by 52 apps in this directory

TypeScript
56%
Other

agenta

AI Development · Developer Tools · Devops

4,788

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript 56%
Python 39%
Updated 1 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers