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.2b0.tar.gz (36.2 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.2b0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_vertexai-2.2b0.tar.gz
Algorithm Hash digest
SHA256 5f25956ff61cf365600b2661371e97be065c16e83079c7e7fe12cd7ea776ff41
MD5 d410913e5ab583c6abdd7f37b49db8fd
BLAKE2b-256 4063132aa3883ec4ce62ad3efd8316a8eb4e1759026230253fb32d96a34ff5b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_vertexai-2.2b0-py3-none-any.whl
Algorithm Hash digest
SHA256 2feed48072c55abcbf4af914359d3ac90ffe4deb3b05db5ed06c3cb21bb1d075
MD5 76a8dc011ab832d4c0573430c3904341
BLAKE2b-256 fb635f4155b8474cbd6bac1d441668a97cb8d5e662513bbd4b9ba8c8632e1533

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