Metadata-Version: 2.3
Name: openinference-instrumentation-vertexai
Version: 0.1.0
Summary: OpenInference VertexAI Instrumentation
Project-URL: homepage, https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-vertexai
Author-email: OpenInference Authors <oss@arize.com>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: <3.13,>=3.8
Requires-Dist: openinference-instrumentation>=0.1.7
Requires-Dist: openinference-semantic-conventions
Requires-Dist: opentelemetry-api
Requires-Dist: opentelemetry-instrumentation
Requires-Dist: opentelemetry-semantic-conventions
Requires-Dist: wrapt
Provides-Extra: instruments
Requires-Dist: google-cloud-aiplatform>=1.49.0; extra == 'instruments'
Provides-Extra: test
Requires-Dist: opentelemetry-sdk; extra == 'test'
Requires-Dist: vertexai==1.49.0; extra == 'test'
Description-Content-Type: text/markdown

# OpenInference Google VertexAI Instrumentation

Python auto-instrumentation library for VertexAI SDK and the Google Cloud AI Platform. Traces are fully OpenTelemetry compatible and can be sent to any OpenTelemetry collector for viewing, such as [Arize Phoenix](https://github.com/Arize-ai/phoenix).

[![pypi](https://badge.fury.io/py/openinference-instrumentation-vertexai.svg)](https://pypi.org/project/openinference-instrumentation-vertexai/)

## Installation

```shell
pip install -Uqqq openinference-instrumentation-vertexai
```

## Quickstart

Install `openinference-instrumentation-vertexai` and `arize-phoenix`.


```shell
pip install -Uqqq openinference-instrumentation-vertexai arize-phoenix
```

Start the `phoenix` server so that it is ready to receive traces.
The `phoenix` server runs entirely on your machine and does not send data over the internet.

```shell
python -m phoenix.server.main serve
```

Instrumenting `vertexai` is simple.

```python
from openinference.instrumentation.vertexai import VertexAIInstrumentor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

endpoint = "http://127.0.0.1:4317"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))

VertexAIInstrumentor().instrument(tracer_provider=tracer_provider)
```

Now, all calls by `generative_models` are instrumented and can be viewed in the `phoenix` UI.

```python
import vertexai
from vertexai.generative_models import GenerativeModel

vertexai.init(location="us-central1")
model = GenerativeModel("gemini-1.5-flash")

print(model.generate_content("Why is sky blue?"))
```

## More Info

More details about tracing with OpenInference and `phoenix` can be found in the [`phoenix` documentation](https://docs.arize.com/phoenix).
