Configure the Netra SDK programmatically when initializing for maximum control over your application’s observability settings. This section covers how to set up the SDK using code parameters.

Basic Configuration

Initialize the SDK with essential parameters:
from netra import Netra
from netra.instrumentation.instruments import InstrumentSet

# Basic configuration
Netra.init(
    app_name="my-ai-service",
    environment="production",
    resource_attributes={"team": "ai", "version": "1.0.0"},
    trace_content=True,
    disable_batch=False,
	instruments={InstrumentSet.OPENAI}
)

Available Parameters

ParameterDescriptionDefaultType
app_nameLogical name for your servicellm_tracing_servicestr
environmentDeployment environment (prod, staging, dev)localstr
resource_attributesCustom resource attributes{}dict
trace_contentWhether to capture prompt/completion contentTruebool
disable_batchDisable batch span processorFalsebool
api_keyAPI key for authenticationNonestr
headersAdditional headers in W3C Correlation-Context formatNonestr

Advanced Configuration

Setting Resource Attributes

Add custom attributes to enrich your tracing data:
# Set resource attributes
Netra.init(
    app_name="my-ai-service",
    resource_attributes={
        "team": "ai",
        "version": "1.0.0",
        "region": "us-east",
        "environment": "production"
    },
	instruments={InstrumentSet.OPENAI}
)

Controlling Content Tracing

Control what content is captured:
# Control content tracing
Netra.init(
    app_name="my-ai-service",
    trace_content=True,  # Capture prompt/completion content
    disable_batch=False  # Enable batch processing,
	instruments={InstrumentSet.OPENAI}
)

Example Configurations

Basic Production Setup

from netra import Netra
from netra.instrumentations.instruments import InstrumentSet

# Basic production configuration
Netra.init(
    app_name="my-production-service",
    environment="production",
    resource_attributes={
        "team": "ai",
        "version": "1.0.0",
        "region": "us-east"
    },
    trace_content=True,
    disable_batch=False,
	instruments={InstrumentSet.OPENAI}
)

Development Setup

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

# Development configuration
Netra.init(
    app_name="my-dev-service",
    environment="development",
    resource_attributes={
        "team": "ai",
        "version": "1.0.0-dev",
        "developer": "john.doe"
    },
    trace_content=True,
    disable_batch=True  # Disable batch in development,
	instruments={InstrumentSet.OPENAI}
)