Initialize the Netra SDK with Vertex AI instrumentation enabled. The SDK automatically traces all Vertex AI API calls once initialized.
from netra import Netrafrom vertexai.preview.generative_models import GenerativeModelimport vertexaiimport os# Initialize Netra with Vertex AI instrumentationNetra.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 tracedvertexai.init(project="your-project-id", location="us-central1")model = GenerativeModel("gemini-pro")response = model.generate_content("What is observability?")print(response.text)
import { Netra } from "netra-sdk";import { VertexAI } from "@google-cloud/vertexai";async function main() { // Initialize Netra with Vertex AI instrumentation (must await) await Netra.init({ appName: "my-ai-app", headers: `x-api-key=${process.env.NETRA_API_KEY}`, traceContent: true }); // Use Vertex AI client as usual - all calls are automatically traced const vertexAI = new VertexAI({ project: "your-project-id", location: "us-central1" }); const model = vertexAI.getGenerativeModel({ model: "gemini-pro" }); const result = await model.generateContent("What is observability?"); const response = await result.response; console.log(response.text());}main();
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="")
const model = vertexAI.getGenerativeModel({ model: "gemini-pro" });const result = await model.generateContentStream("Tell me a story");for await (const chunk of result.stream) { const chunkText = chunk.text(); process.stdout.write(chunkText);}
Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netrafrom netra.instrumentation.instruments import InstrumentSet# Only enable Vertex AI instrumentationNetra.init( headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", instruments={InstrumentSet.VERTEXAI})# Or block specific instrumentationsNetra.init( headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", block_instruments={InstrumentSet.HTTPX})
import { Netra, NetraInstruments } from "netra-sdk";// Only enable Vertex AI instrumentationawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, instruments: new Set([NetraInstruments.VERTEXAI])});// Or block specific instrumentationsawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, blockInstruments: new Set([NetraInstruments.HTTP])});