Skip to main content

View on PyPI

netra-sdk on Python Package Index

Source on GitHub

View source code and contribute

Installation

Netra Class

The Netra 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.
Parameters: Returns: None

start_span

Create a new span for manual tracing. Use as a context manager for automatic span lifecycle management.
Parameters: Returns: SpanWrapper instance

set_session_id

Set the session ID for the current context. All subsequent spans will be associated with this session.
Parameters: Returns: None

set_user_id

Set the user ID for the current context.
Parameters: Returns: None

set_tenant_id

Set the tenant ID for multi-tenant applications.
Parameters: Returns: None

set_custom_attributes

Add custom key-value attributes to the current context.
Parameters: Returns: None

set_custom_event

Record a custom event in the current context.
Parameters: Returns: None

add_conversation

Append a conversation entry to the current span. Useful for tracking multi-turn conversations.
Parameters: 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.
Parameters: 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.
Parameters: 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.
Parameters: 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.
Parameters: 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.
Returns: None

SpanWrapper Class

The SpanWrapper 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.
Parameters: Returns: SpanWrapper (for chaining)

add_event

Record a timestamped event within the span.
Parameters: Returns: SpanWrapper (for chaining)

set_prompt

Set the input prompt for LLM spans.
Parameters: Returns: SpanWrapper (for chaining)

set_negative_prompt

Set the negative prompt (commonly used for image generation).
Parameters: Returns: SpanWrapper (for chaining)

set_model

Set the model name used in the operation.
Parameters: Returns: SpanWrapper (for chaining)

set_llm_system

Set the LLM provider/system name.
Parameters: Returns: SpanWrapper (for chaining)

set_usage

Record token usage and cost metrics.
Parameters: Returns: SpanWrapper (for chaining)

set_action

Track actions or tool calls within the span.
Parameters: Returns: SpanWrapper (for chaining)

set_success

Mark the span as successful.
Returns: SpanWrapper (for chaining)

set_error

Mark the span as failed with an error message.
Parameters: Returns: SpanWrapper (for chaining)

Models

SpanType

Enum for categorizing spans.

UsageModel

Model for tracking token usage and costs.
Fields:

ActionModel

Model for tracking actions and tool calls.
Fields:

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 parameter capture_internal_methods that let’s you trace both private and dunder methods when used on a Class

Dashboard Client

The dashboard 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.
Parameters: Returns: dict | Any

get_session_summary

Retrieve aggregated session metrics including total sessions, costs, and latency.
Parameters: 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.
Parameters: Returns: dict | Any

get_session_stats

Fetch a paginated list of sessions with individual metrics.
Parameters: Returns: SessionStatsResult

iter_session_stats

Iterator that automatically handles pagination for session stats.
Parameters: Returns: Iterator[SessionStatsResult]
For detailed documentation on all dashboard enums, types, and filtering options, see Dashboard Query.

Usage Client

The usage client provides methods to query usage metrics, list traces, and fetch span data.

get_session_usage

Fetch usage metrics for a single session.
Parameters: Returns: SessionUsageData | Any

get_tenant_usage

Fetch aggregated usage metrics for a tenant.
Parameters: Returns: TenantUsageData | Any

list_traces

Query traces for a time range with optional filtering and pagination.
Parameters: Returns: TracesPage | Any

iter_traces

Iterator that automatically handles pagination for traces.
Returns: Iterator[TraceSummary]

list_spans_by_trace_id

Fetch spans within a single trace.
Parameters: Returns: SpansPage | Any

iter_spans_by_trace_id

Iterator that automatically handles pagination for spans.
Returns: 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

When instruments is not specified, Netra uses the following curated set (DEFAULT_INSTRUMENTS):

Default Root Instruments

When root_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

Last modified on July 31, 2026