Skip to main content

OpenTelemetry Official VertexAI instrumentation

Project description

pypi

This library allows tracing LLM requests and logging of messages made by the VertexAI Python API library.

Installation

If your application is already instrumented with OpenTelemetry, add this package to your requirements.

pip install opentelemetry-instrumentation-vertexai

If you don’t have an VertexAI application, yet, try our examples.

Check out zero-code example for a quick start.

Usage

This section describes how to set up VertexAI 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 VertexAI chat completion operations. You can also optionally capture prompts and completions as log events.

Make sure to configure OpenTelemetry tracing, logging, and events to capture all telemetry emitted by the instrumentation.

from opentelemetry.instrumentation.vertexai import VertexAIInstrumentor
from vertexai.generative_models import GenerativeModel

VertexAIInstrumentor().instrument()


vertexai.init()
model = GenerativeModel("gemini-1.5-flash-002")
response = model.generate_content("Write a short poem on OpenTelemetry.")

Enabling message content

Message content such as the contents of the prompt, completion, function arguments and return values are not captured by default. To capture message content as log events, set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to true.

Uninstrument

To uninstrument clients, call the uninstrument method:

from opentelemetry.instrumentation.vertexai import VertexAIInstrumentor

VertexAIInstrumentor().instrument()
# ...

# Uninstrument all clients
VertexAIInstrumentor().uninstrument()

References

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentelemetry_instrumentation_vertexai-2.1b0.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file opentelemetry_instrumentation_vertexai-2.1b0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_vertexai-2.1b0.tar.gz
Algorithm Hash digest
SHA256 29cd7a0a781d736e3bd9a0707c0a529c1ab086e90d1733cf53940d41c46f9bba
MD5 047e027e5b187ae9ab789b2b733b1b9d
BLAKE2b-256 6c598240e44b374ebdaaf8b6fc4aa48e31ec7dae1c535b3244997fc8b03c7607

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation_vertexai-2.1b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_vertexai-2.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 e140b69af3c78ed8b6b399d5f47875f1645abdc58010a9dee52bafc0ee6f93a2
MD5 5fdefdbef58122273df3436612cb60dd
BLAKE2b-256 0a4a6fe1fc472e29b1ae5024f0e932231aaa133d1d4567a24ba3644fd75f171c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page