View on PyPI
netra-sdk on Python Package Index
Source on GitHub
View source code and contribute
Installation
Netra Class
TheNetra class is the main entry point for all SDK operations. All methods are static and can be called directly on the class.
init
Initialize the Netra SDK with configuration options. Call this once at the start of your application.
Returns:
None
start_span
Create a new span for manual tracing. Use as a context manager for automatic span lifecycle management.
Returns:
SpanWrapper instance
set_session_id
Set the session ID for the current context. All subsequent spans will be associated with this session.
Returns:
None
set_user_id
Set the user ID for the current context.
Returns:
None
set_tenant_id
Set the tenant ID for multi-tenant applications.
Returns:
None
set_custom_attributes
Add custom key-value attributes to the current context.
Returns:
None
set_custom_event
Record a custom event in the current context.
Returns:
None
add_conversation
Append a conversation entry to the current span. Useful for tracking multi-turn conversations.
Returns:
None
If you’re using Netra’s auto-instrumentation for LLM calls, conversation messages are captured automatically. Using this method may result in duplicate messages.
set_input
Set the input value on the current active span. Useful for explicitly recording what was passed into a step or function.
Returns:
None
The value is truncated to the SDK’s maximum attribute length. If you’re using auto-instrumentation for LLM calls, inputs may already be captured — use this method only when you need to set or override the input explicitly.
set_output
Set the output value on the current active span. Useful for explicitly recording the result produced by a step or function.
Returns:
None
The value is truncated to the SDK’s maximum attribute length. If you’re using auto-instrumentation for LLM calls, outputs may already be captured — use this method only when you need to set or override the output explicitly.
set_root_input
Set the input value on the root span of the current trace. This is useful for recording the top-level input to your entire pipeline, regardless of which nested span is currently active.
Returns:
None
The root span is the oldest span in the current trace. If no root span has been registered, this falls back to the current active span. The value is truncated to the SDK’s maximum attribute length.
set_root_output
Set the output value on the root span of the current trace. This is useful for recording the final result of your entire pipeline, regardless of which nested span is currently active.
Returns:
None
The root span is the oldest span in the current trace. If no root span has been registered, this falls back to the current active span. The value is truncated to the SDK’s maximum attribute length.
shutdown
Gracefully shutdown the SDK, flushing any pending spans.None
SpanWrapper Class
TheSpanWrapper class provides methods for enriching spans with additional context. It’s returned by Netra.start_span() and supports method chaining.
set_attribute
Add a custom attribute to the span.
Returns:
SpanWrapper (for chaining)
add_event
Record a timestamped event within the span.
Returns:
SpanWrapper (for chaining)
set_prompt
Set the input prompt for LLM spans.
Returns:
SpanWrapper (for chaining)
set_negative_prompt
Set the negative prompt (commonly used for image generation).
Returns:
SpanWrapper (for chaining)
set_model
Set the model name used in the operation.
Returns:
SpanWrapper (for chaining)
set_llm_system
Set the LLM provider/system name.
Returns:
SpanWrapper (for chaining)
set_usage
Record token usage and cost metrics.
Returns:
SpanWrapper (for chaining)
set_action
Track actions or tool calls within the span.
Returns:
SpanWrapper (for chaining)
set_success
Mark the span as successful.SpanWrapper (for chaining)
set_error
Mark the span as failed with an error message.
Returns:
SpanWrapper (for chaining)
Models
SpanType
Enum for categorizing spans.UsageModel
Model for tracking token usage and costs.ActionModel
Model for tracking actions and tool calls.ConversationType
Enum for conversation entry types.Decorators
The SDK provides decorators for easy function instrumentation.@agent
Mark a function or class as an AI agent.@task
Mark a function or class as a task or tool.@workflow
Mark a function or class as a workflow.Capture Internal Methods
All decorators support the optional parametercapture_internal_methods that let’s you trace both private and dunder methods when used on a Class
Dashboard Client
Thedashboard client provides methods to query dashboard data, session summaries, session statistics, and full session details programmatically.
query_data
Fetch dashboard data with customizable metrics, dimensions, and filters.
Returns:
dict | Any
get_session_summary
Retrieve aggregated session metrics including total sessions, costs, and latency.
Returns:
dict | Any
get_session_detail
Retrieve full details for a single session, including traces, tokens, costs, and tool calls.get_session_details is available in the Python SDK only.
Returns:
dict | Any
get_session_stats
Fetch a paginated list of sessions with individual metrics.
Returns:
SessionStatsResult
iter_session_stats
Iterator that automatically handles pagination for session stats.
Returns:
Iterator[SessionStatsResult]
For detailed documentation on all dashboard enums, types, and filtering options, see Dashboard Query.
Usage Client
Theusage client provides methods to query usage metrics, list traces, and fetch span data.
get_session_usage
Fetch usage metrics for a single session.
Returns:
SessionUsageData | Any
get_tenant_usage
Fetch aggregated usage metrics for a tenant.
Returns:
TenantUsageData | Any
list_traces
Query traces for a time range with optional filtering and pagination.
Returns:
TracesPage | Any
iter_traces
Iterator that automatically handles pagination for traces.Iterator[TraceSummary]
list_spans_by_trace_id
Fetch spans within a single trace.
Returns:
SpansPage | Any
iter_spans_by_trace_id
Iterator that automatically handles pagination for spans.Iterator[TraceSpan]
For detailed documentation on response types and all filtering options, see Usage, Traces & Spans.
Instruments
Available instrumentations for auto-tracing.When
instruments is not specified in Netra.init(), only the curated DEFAULT_INSTRUMENTS set is enabled — not every library listed below. Pass InstrumentSet.ALL to instrument all supported libraries, or pass an explicit set to pick exactly what you need. See Instrumentation Selection for details.ALL Sentinel
LLM Providers
AI Frameworks
Vector Databases
HTTP Clients
Web Frameworks
Databases
Message Queues
Other
Default Instruments
Wheninstruments is not specified, Netra uses the following curated set (DEFAULT_INSTRUMENTS):
Default Root Instruments
Whenroot_instruments is not specified, Netra uses the following curated subset (DEFAULT_INSTRUMENTS_FOR_ROOT). Libraries in this set are allowed to produce root-level spans (top-level traces):
In agentic applications, a single invocation can be captured by multiple instrumentations across frameworks and LLM providers. For example, an OpenAI call made through Agno may be traced by both the Agno and OpenAI instrumentations. This can lead to duplicated telemetry data, such as token usage and cost, within the same trace. Review your traces carefully to identify such overlaps, and disable unnecessary instrumentations when required to ensure accurate observability data.
Complete Example
Next Steps
- TypeScript SDK Reference - TypeScript/JavaScript API reference
- Dashboard Query - Complete dashboard API reference
- Usage Utilities - Query traces and usage data
- Auto-Instrumentation - Automatic tracing setup
- Instrumentation Selection - Control which libraries are instrumented
- Manual Tracing - Advanced tracing patterns
- Decorators - Using decorators effectively
