Skip to main content
Netra provides official SDKs for Python and TypeScript/JavaScript, enabling you to instrument your AI applications with minimal code changes.

Available SDKs

Installation

pip install netra-sdk

Quick Start

Initialize the SDK at the start of your application:
from netra import Netra

Netra.init(
    app_name="my-ai-app",
    environment="production",
    headers=f"x-api-key={os.getenv('NETRA_API_KEY')}",
)

Core Features

Both SDKs provide the same core functionality:
FeatureDescription
Auto-InstrumentationAutomatic tracing for 50+ LLM providers, frameworks, and databases
Manual TracingCreate custom spans with full control over attributes and events
DecoratorsSimple function decoration for @agent, @task, and @workflow
Context TrackingSet user, session, and tenant IDs for filtering and analysis
Usage TrackingRecord token usage, costs, and custom metrics

SDK Architecture

┌─────────────────────────────────────────────────────────┐
│                    Your Application                      │
├─────────────────────────────────────────────────────────┤
│                      Netra SDK                          │
│  ┌──────────────┐ ┌──────────────┐ ┌──────────────┐    │
│  │    Auto-     │ │   Manual     │ │  Decorators  │    │
│  │Instrumentation│ │   Tracing    │ │              │    │
│  └──────────────┘ └──────────────┘ └──────────────┘    │
│  ┌──────────────────────────────────────────────────┐  │
│  │              OpenTelemetry Core                   │  │
│  └──────────────────────────────────────────────────┘  │
├─────────────────────────────────────────────────────────┤
│                    OTLP Exporter                        │
└─────────────────────────────────────────────────────────┘


                    Netra Cloud /
                    Custom Backend

Main Classes

Netra (Static Class)

The main entry point for SDK operations:
MethodDescription
init()Initialize the SDK with configuration
start_span()Create a new span for manual tracing
get_current_span()Get the currently active span
set_user_id()Set user context for traces
set_session_id()Set session context for traces
set_tenant_id()Set tenant context for traces
set_custom_attributes()Add custom key-value attributes
set_custom_event()Record a custom event
shutdown()Gracefully shutdown the SDK

SpanWrapper

Returned by start_span(), provides methods to enrich spans:
MethodDescription
set_attribute()Add a custom attribute
add_event()Record an event within the span
set_prompt()Set the input prompt (for LLM spans)
set_model()Set the model name
set_usage()Record usage metrics
set_action()Track actions/tool calls
set_success()Mark span as successful
set_error()Mark span as failed with error message
end()End the span (TypeScript only)

Models

ModelDescription
UsageModelToken usage and cost tracking
ActionModelAction/tool call tracking
SpanTypeEnum for span categorization

Environment Variables

Configure the SDK via environment variables:
VariableDescription
NETRA_API_KEYAPI key for authentication
NETRA_APP_NAMEApplication name
NETRA_ENVEnvironment (production, staging, etc.)
NETRA_OTLP_ENDPOINTCustom OTLP endpoint URL
NETRA_TRACE_CONTENTEnable/disable content tracing
NETRA_DEBUGEnable debug logging

Next Steps

Last modified on January 30, 2026