Trace IBM Watsonx AI model calls with Netra auto-instrumentation. Monitor foundation model prompts, completions, token usage, and latency on IBM Cloud.
The SDK automatically handles streaming responses and captures the complete output:
model = Model( model_id="ibm/granite-13b-chat-v2", credentials={ "url": "https://us-south.ml.cloud.ibm.com", "apikey": os.environ.get("WATSONX_API_KEY") }, project_id=os.environ.get("WATSONX_PROJECT_ID"))for chunk in model.generate_text_stream(prompt="Tell me a story"): print(chunk, end="")
const stream = await watsonx.generateTextStream({ input: "Tell me a story", modelId: "ibm/granite-13b-chat-v2", projectId: process.env.WATSONX_PROJECT_ID});for await (const chunk of stream) { if (chunk.results && chunk.results[0]) { process.stdout.write(chunk.results[0].generated_text); }}
Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netrafrom netra.instrumentation.instruments import InstrumentSet# Only enable Watsonx instrumentationNetra.init( headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", instruments={InstrumentSet.WATSONX})# 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 Watsonx instrumentationawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, instruments: new Set([NetraInstruments.WATSONX])});// Or block specific instrumentationsawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, blockInstruments: new Set([NetraInstruments.HTTP])});