Trace and monitor OpenAI GPT model calls with Netra auto-instrumentation. Capture prompts, completions, token usage, and latency with zero code changes.
The SDK automatically handles streaming responses and captures the complete output:
stream = client.chat.completions.create( model="gpt-4", messages=[{"role": "user", "content": "Tell me a story"}], stream=True)for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")
const stream = await openai.chat.completions.create({ model: "gpt-4", messages: [{ role: "user", content: "Tell me a story" }], stream: true});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || "");}
Embedding operations are also automatically instrumented:
embedding = client.embeddings.create( model="text-embedding-ada-002", input="The quick brown fox jumps over the lazy dog")print(embedding.data[0].embedding)
const embedding = await openai.embeddings.create({ model: "text-embedding-ada-002", input: "The quick brown fox jumps over the lazy dog"});console.log(embedding.data[0].embedding);
Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netrafrom netra.instrumentation.instruments import InstrumentSet# Only enable OpenAI instrumentationNetra.init( headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", instruments={InstrumentSet.OPENAI})# 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 OpenAI instrumentationawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, instruments: new Set([NetraInstruments.OPENAI])});// Or block specific instrumentationsawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, blockInstruments: new Set([NetraInstruments.HTTP])});