Initialize the Netra SDK with Replicate instrumentation enabled. The SDK automatically traces all Replicate API calls once initialized.
from netra import Netraimport replicateimport os# Initialize Netra with Replicate instrumentationNetra.init( app_name="my-ai-app", headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", trace_content=True)# Use Replicate client as usual - all calls are automatically tracedoutput = replicate.run( "meta/llama-2-70b-chat:latest", input={"prompt": "What is observability?"})print(output)
import { Netra } from "netra-sdk";import Replicate from "replicate";async function main() { // Initialize Netra with Replicate instrumentation (must await) await Netra.init({ appName: "my-ai-app", headers: `x-api-key=${process.env.NETRA_API_KEY}`, traceContent: true }); // Use Replicate client as usual - all calls are automatically traced const replicate = new Replicate({ auth: process.env.REPLICATE_API_TOKEN }); const output = await replicate.run( "meta/llama-2-70b-chat:latest", { input: { prompt: "What is observability?" } } ); console.log(output);}main();
The SDK automatically handles streaming responses and captures the complete output:
for event in replicate.stream( "meta/llama-2-70b-chat:latest", input={"prompt": "Tell me a story"}): print(event, end="")
for await (const event of replicate.stream( "meta/llama-2-70b-chat:latest", { input: { prompt: "Tell me a story" } })) { process.stdout.write(event.toString());}
Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netrafrom netra.instrumentation.instruments import InstrumentSet# Only enable Replicate instrumentationNetra.init( headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", instruments={InstrumentSet.REPLICATE})# 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 Replicate instrumentationawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, instruments: new Set([NetraInstruments.REPLICATE])});// Or block specific instrumentationsawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, blockInstruments: new Set([NetraInstruments.HTTP])});