Skip to main content

Installation

Install both the Netra SDK and Google Cloud Vertex AI SDK:
pip install netra-sdk google-cloud-aiplatform

Usage

Initialize the Netra SDK with Vertex AI instrumentation enabled. The SDK automatically traces all Vertex AI API calls once initialized.
from netra import Netra
from vertexai.preview.generative_models import GenerativeModel
import vertexai
import os

# Initialize Netra with Vertex AI instrumentation
Netra.init(
    app_name="my-ai-app",
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    trace_content=True
)

# Use Vertex AI client as usual - all calls are automatically traced
vertexai.init(project="your-project-id", location="us-central1")

model = GenerativeModel("gemini-pro")

response = model.generate_content("What is observability?")
print(response.text)

Streaming Responses

The SDK automatically handles streaming responses and captures the complete output:
model = GenerativeModel("gemini-pro")

responses = model.generate_content("Tell me a story", stream=True)

for response in responses:
    print(response.text, end="")

Chat Sessions

Chat operations are also automatically instrumented:
model = GenerativeModel("gemini-pro")

chat = model.start_chat()

response1 = chat.send_message("Hello")
print(response1.text)

response2 = chat.send_message("What is machine learning?")
print(response2.text)

Selective Instrumentation

Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netra
from netra.instrumentation.instruments import InstrumentSet

# Only enable Vertex AI instrumentation
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    instruments={InstrumentSet.VERTEXAI}
)

# Or block specific instrumentations
Netra.init(
    headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
    block_instruments={InstrumentSet.HTTPX}
)

Next Steps

Last modified on February 3, 2026