Skip to main content
The Netra.init() function configures the SDK and starts the tracing system. Call it once at the start of your application, before making any LLM or database calls.

Quick Start

from netra import Netra

Netra.init(
    app_name="my-ai-app",
    environment="production",
)

Configuration Parameters

ParameterTypeDefaultDescription
app_name / appNamestringRequiredApplication name for identifying traces in the dashboard
environmentstring"default" (Py) / "local" (TS)Deployment environment (e.g., production, staging, development)
headersstring""Authentication headers, typically x-api-key=YOUR_KEY
trace_content / traceContentbooleantrueCapture prompt/completion content from LLM calls. Disable for privacy.
debug_mode / debugModebooleanfalseEnable verbose logging for troubleshooting
disable_batch / disableBatchbooleanfalseSend spans immediately instead of batching
enable_root_span / enableRootSpanbooleanfalseCreate a root span for the entire process (useful for workers)
resource_attributes / resourceAttributesdict/object{}Custom attributes added to every span
blocked_spans / blockedSpanslist/array[]Span name patterns to exclude (supports * wildcards)
enable_scrubbingbooleanfalseAuto-redact detected PII (Python only)
instrumentsSet/listAllSpecific instrumentations to enable
block_instruments / blockInstrumentsSet/list[]Instrumentations to disable
For instrumentation control details, see Instrumentation Selection.

Complete Example

import os
from netra import Netra
from netra.instrumentation.instruments import InstrumentSet

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

    # Content and privacy
    trace_content=True,
    enable_scrubbing=False,

    # Performance
    disable_batch=False,

    # Debugging
    debug_mode=False,

    # Long-running processes
    enable_root_span=False,

    # Custom metadata added to all spans
    resource_attributes={
        "service.version": os.getenv("APP_VERSION"),
        "deployment.region": os.getenv("AWS_REGION"),
        "team": "ml-platform",
    },

    # Span filtering (supports wildcards)
    blocked_spans=[
        "health-check",   # Exact match
        "internal.*",     # Prefix match
        "*.debug",        # Suffix match
    ],

    # Instrumentation control
    block_instruments={
        InstrumentSet.HTTPX,
        InstrumentSet.REQUESTS,
    },
)
PII scrubbing (enable_scrubbing) adds processing overhead. Only enable when handling sensitive data.

Configuration Precedence

Configuration values are resolved in order of priority:
  1. Code parameters - Values passed to Netra.init()
  2. Netra environment variables - NETRA_* variables
  3. OpenTelemetry environment variables - OTEL_* variables
  4. Default values - SDK defaults

Async Initialization (TypeScript)

The Netra.init() method in TypeScript is async and waits for all instrumentations to be ready before returning. Always await the call to ensure proper instrumentation:
TypeScript
async function main() {
  // init() is async and waits for instrumentations to be ready
  await Netra.init({
    appName: "my-ai-app",
    environment: "production",
  });
  // SDK is fully initialized, all instrumentations are patched
}
Always await Netra.init() to ensure libraries like OpenAI, Anthropic, and LangGraph are properly instrumented before use. This is especially important in frameworks like NestJS where modules are loaded after initialization.

Shutdown

Ensure all pending spans are exported before application exit:
Netra.shutdown()
Always call shutdown() before exit, especially for short-lived processes like serverless functions.

Next Steps

Last modified on February 3, 2026