Skip to main content

OpenTelemetry instrumentation for Vertex AI

Project description

VertexAI OpenTelemetry Integration

Overview

This integration provides support for using OpenTelemetry with the VertexAI framework. It enables tracing and monitoring of applications built with VertexAI.

Installation

  1. Install traceAI VertexAI
pip install traceAI-vertexai
  1. Install VertexAI SDK
pip install vertexai

Set Environment Variables

Set up your environment variables to authenticate with FutureAGI

import os

os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = GOOGLE_APPLICATION_CREDENTIALS

Quickstart

Register Tracer Provider

Set up the trace provider to establish the observability pipeline. The trace provider:

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="vertexai_app"
)

Configure VertexAI Instrumentation

Instrument the VertexAI client to enable telemetry collection. This step ensures that all interactions with the VertexAI SDK are tracked and monitored.

from traceai_vertexai import VertexAIInstrumentor

VertexAIInstrumentor().instrument(tracer_provider=trace_provider)

Create VertexAI Components

Set up your VertexAI client with built-in observability.

import vertexai
from vertexai.generative_models import FunctionDeclaration, GenerativeModel, Part, Tool

vertexai.init(
    project="project_name",
)

# Describe a function by specifying its schema (JsonSchema format)
get_current_weather_func = FunctionDeclaration(
    name="get_current_weather",
    description="Get the current weather in a given location",
    parameters={
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA",
            },
            "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
        },
        "required": ["location"],
    },
)

# Tool is a collection of related functions
weather_tool = Tool(function_declarations=[get_current_weather_func])

# Use tools in chat
chat = GenerativeModel("gemini-1.5-flash", tools=[weather_tool]).start_chat()

if __name__ == "__main__":
    for response in chat.send_message(
        "What is the weather like in Boston?", stream=True
    ):
        print(response)
    for response in chat.send_message(
        Part.from_function_response(
            name="get_current_weather",
            response={"content": {"weather": "super nice"}},
        ),
        stream=True,
    ):
        print(response)

Project details


Download files

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

Source Distribution

traceai_vertexai-0.1.8.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

traceai_vertexai-0.1.8-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file traceai_vertexai-0.1.8.tar.gz.

File metadata

  • Download URL: traceai_vertexai-0.1.8.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_vertexai-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7a6b8b673956f4473cea60bb6268d32c625be05e6f4fbadd4bb5fb3d0c501d79
MD5 765f64756643c96d8f8aada814bec922
BLAKE2b-256 1dd15d899d0959f97577e60b51774affb3a2da0fa0cd08f183437739b5707e8a

See more details on using hashes here.

File details

Details for the file traceai_vertexai-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: traceai_vertexai-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_vertexai-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a1896758dd72bff02455ce3829ab88781a9ab59b145768ccef35a86e4d73770a
MD5 213700ef060f6891929e3fa21416e22c
BLAKE2b-256 f6008fe25f158c96da48a22c75bf7bcbb9ccc1636b0e2c371587f21ad85e066a

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