For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
  • Python SDK
    • Overview
    • Initialize
    • Log Batch Results
      • OpenAI Agents
      • OpenAI
      • OpenInference
      • Google ADK
      • Vertex AI
      • Superagent
    • Instrumentation Protocol
    • API Client
  • TypeScript SDK
    • Overview
    • Initialize
    • Log Batch Results
    • API Client
LogoLogo
DiscordPlatform
On this page
  • Overview
  • Dependencies
  • Quick start
  • Public API
  • VertexAIInstrumentor
  • Captured calls
  • Span attributes
  • With propagated attributes
  • Internal modules
Python SDKInstrumentations

Vertex AI

Was this page helpful?
Previous

Superagent

Next
Built with

Overview

respan-instrumentation-vertexai captures calls made through the Google Vertex AI Python SDK and sends them to Respan through the unified OTEL pipeline.

The package patches vertexai.generative_models.GenerativeModel and ChatSession methods, including sync calls, async calls, and streaming responses. It emits canonical gen_ai.*, llm.*, and traceloop.entity.* attributes for Respan chat logs.

$pip install respan-instrumentation-vertexai google-cloud-aiplatform

Version: 0.1.0 | Python: >=3.11, <3.14

Dependencies

PackageVersion
respan-tracing^2.17.0
respan-sdk>=2.6.1
google-cloud-aiplatform>=1.71.0
opentelemetry-semantic-conventions-ai>=0.4.1

Quick start

1import vertexai
2from respan import Respan
3from respan_instrumentation_vertexai import VertexAIInstrumentor
4from vertexai.generative_models import GenerativeModel
5
6respan = Respan(instrumentations=[VertexAIInstrumentor()])
7
8vertexai.init(project="your-gcp-project", location="us-central1")
9
10model = GenerativeModel("gemini-2.0-flash")
11response = model.generate_content("Say hello in three languages.")
12print(response.text)
13respan.flush()

Public API

VertexAIInstrumentor

The main instrumentor class. Implements the Instrumentation protocol.

1from respan_instrumentation_vertexai import VertexAIInstrumentor
Attribute/MethodTypeDescription
namestr"vertexai" - unique plugin identifier.
activate()() -> NonePatches Vertex AI generation and chat methods.
deactivate()() -> NoneRestores the original Vertex AI methods.

Captured calls

Vertex AI operationLog TypeDescription
GenerativeModel.generate_content()chatSync generation calls, including streamed iterators.
GenerativeModel.generate_content_async()chatAsync generation calls, including async streams.
ChatSession.send_message()chatSync chat turns, including streamed iterators.
ChatSession.send_message_async()chatAsync chat turns.

Span attributes

LLM spans include:

AttributeDescription
respan.entity.log_typechat for Vertex AI model calls.
gen_ai.systemgoogle.
gen_ai.request.modelVertex AI model name.
llm.request.typechat.
llm.request.functionsJSON-serialized function declarations when tools are provided.
gen_ai.prompt.N.role / gen_ai.prompt.N.contentPrompt roles and message content.
gen_ai.completion.0.role / gen_ai.completion.0.contentAssistant response role and content.
gen_ai.completion.0.tool_callsJSON-serialized model function calls when returned.
gen_ai.usage.input_tokens / gen_ai.usage.output_tokensModern token usage fields.
gen_ai.usage.prompt_tokens / gen_ai.usage.completion_tokensLegacy token usage aliases emitted for compatibility.
llm.usage.total_tokensTotal token count when provided by Vertex AI.

With propagated attributes

Use propagate_attributes() to attach per-request metadata to all spans:

1from respan import Respan, propagate_attributes
2from respan_instrumentation_vertexai import VertexAIInstrumentor
3
4respan = Respan(instrumentations=[VertexAIInstrumentor()])
5
6with propagate_attributes(
7 customer_identifier="user_123",
8 trace_group_identifier="vertexai_support_flow",
9 metadata={"source": "support"},
10):
11 response = model.generate_content("Summarize this support ticket.")

Internal modules

These are implementation details, not part of the public API:

ModuleDescription
_instrumentation.pyVertexAIInstrumentor class and method patching.
_translator.pyVertex AI payload normalization helpers.
_otel_emitter.pySynthetic OTEL span construction and injection.
_constants.pyVertex-AI-specific raw field and method names.