OpenInference VertexAI Instrumentation
raw JSON → 0.1.13 verified Fri May 01 auth: no python
OpenInference instrumentation for Google Vertex AI model calls, enabling tracing and observability via OpenTelemetry. Version 0.1.13 supports Python 3.10-3.13. Actively maintained.
pip install openinference-instrumentation-vertexai Common errors
error ModuleNotFoundError: No module named 'openinference_instrumentation_vertexai' ↓
cause Incorrect import path using dots instead of underscores.
fix
Install the package and import with underscores:
pip install openinference-instrumentation-vertexai and from openinference_instrumentation_vertexai import VertexAIInstrumentor. error OpenTelemetry spans not appearing in the backend ↓
cause Missing or misconfigured OpenTelemetry exporter or span processor.
fix
Ensure you have set up a TracerProvider with an exporter (e.g., OTLPSpanExporter) and added a span processor before instrumentation.
Warnings
gotcha Instrumentation must be done before any Vertex AI client calls (e.g., before vertexai.init). ↓
fix Call VertexAIInstrumentor().instrument() before vertexai.init(...).
gotcha This instrumentation only captures synchronous calls; async Vertex AI methods (e.g., with asyncio) may not be traced. ↓
fix For async support, consider using the underlying gRPC instrumentation or waiting for future releases.
Imports
- VertexAIInstrumentor wrong
from openinference.instrumentation.vertexai import VertexAIInstrumentorcorrectfrom openinference_instrumentation_vertexai import VertexAIInstrumentor
Quickstart
from openinference_instrumentation_vertexai import VertexAIInstrumentor
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
import vertexai
import os
# Set up OpenTelemetry tracing
provider = TracerProvider()
exporter = OTLPSpanExporter(endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', ''))
provider.add_span_processor(SimpleSpanProcessor(exporter))
trace.set_tracer_provider(provider)
# Instrument Vertex AI
VertexAIInstrumentor().instrument()
# Now use Vertex AI normally
vertexai.init(project=os.environ.get('GOOGLE_CLOUD_PROJECT', ''), location='us-central1')