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.9.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.9-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: traceai_vertexai-0.1.9.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.9.tar.gz
Algorithm Hash digest
SHA256 02d9559ea1ac036d316ec98aa93b59f920972ad95293bee740c02aa6a42d835c
MD5 1961fb0f6488f71dd05ae2d274c119b7
BLAKE2b-256 574e16ec617a6277100a32d6bb2f265c5608a63b317fa36af452be14806ece2a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: traceai_vertexai-0.1.9-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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6d0596f26bc93fa6056ec4e38975bb25e15b00117688dbe5b6de659552383087
MD5 348268a469b2e73ff818861cfead8330
BLAKE2b-256 39f0dd074675b8a81284f3db2f1f77694de39de763e00380e8a11b746320efdc

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