Track external API calls and custom operations with detailed observability
Netra’s manual tracing capabilities allow you to track external API calls and custom operations with detailed observability. This section covers how to use the custom span tracking utility to monitor your application’s behavior at a granular level.
from netra import Netra, UsageModel, ActionModelfrom netra.instrumentation.instruments import InstrumentSet# Initialize the SDK (if not already initialized)Netra.init(app_name="Your Application Name", instruments={InstrumentSet.OPENAI})# Start a new spanwith Netra.start_span("image_generation") as span: # Your API calls or operations here # ...
You can add various attributes to your spans to provide more context about the operation:
Copy
# Set span attributesspan.set_prompt("A beautiful sunset over mountains")span.set_negative_prompt("blurry, low quality")span.set_model("dall-e-3")span.set_llm_system("openai")
Enable custom action tracking in your application using our action tracking utility. The action tracking utility in Netra follows the given schema:
Copy
[ { "action": str, # Type of action (e.g., "DB", "API", "CACHE") "action_type": str, # Action subtype (e.g., "INSERT", "SELECT", "CALL") "affected_records": [ # Optional: List of records affected { "record_id": str, # ID of the affected record "record_type": str # Type of the record } ], "metadata": Dict[str, str], # Additional metadata as key-value pairs "success": bool # Whether the action succeeded }]
Refer the sample code given to understand how to implement action tracking utility in your application.