Skip to main content

Netra Class

init

def init(
    app_name: Optional[str] = None,
    headers: Optional[str] = None,
    disable_batch: Optional[bool] = None,
    trace_content: Optional[bool] = None,
    resource_attributes: Optional[Dict[str, Any]] = None,
    environment: Optional[str] = None,
    instruments: Optional[Set[NetraInstruments]] = None,
    block_instruments: Optional[Set[NetraInstruments]] = None,
    enable_root_span: Optional[bool] = None,
    debug_mode: Optional[bool] = None,
    enable_scrubbing: Optional[bool] = None,
    blocked_spans: Optional[List[str]] = None,
) -> None
  • Description: Initialize the Netra SDK with configuration options
  • Parameters:
    • app_name (Optional[str]): Name of the application for tracing
    • headers (Optional[str]): Headers for API requests (e.g., API keys)
    • disable_batch (Optional[bool]): Disable batch processing of spans
    • trace_content (Optional[bool]): Enable tracing of content
    • resource_attributes (Optional[Dict[str, Any]]): Additional resource attributes
    • environment (Optional[str]): Application environment (e.g., “production”, “development”)
    • instruments (Optional[Set[NetraInstruments]]): Set of instruments to enable
    • block_instruments (Optional[Set[NetraInstruments]]): Set of instruments to block
    • enable_root_span (Optional[bool]): Enable root span to trace the entire application in a single trace
    • debug_mode (Optional[bool]): Enable debug mode to get application logs
    • enable_scrubbing (Optional[bool]): Enable scrubbing of sensitive data
    • blocked_spans (Optional[List[str]]): List of spans to block globally within the trace. Supports wildcard matching. Please note that to maintain the trace structure while using this utitlity, you need to set the disable_batch parameter to False.
  • Returns: None

set_session_id

def set_session_id(session_id: str) -> None
  • Description: Set session ID context attributes in the current OpenTelemetry context
  • Parameters:
    • session_id (str): Unique identifier for the session
  • Returns: None

set_user_id

def set_user_id(user_id: str) -> None
  • Description: Set user ID context attributes in the current OpenTelemetry context
  • Parameters:
    • user_id (str): Unique identifier for the user
  • Returns: None

set_tenant_id

def set_tenant_id(tenant_id: str) -> None
  • Description: Set tenant ID context attributes in the current OpenTelemetry context
  • Parameters:
    • tenant_id (str): Unique identifier for the tenant
  • Returns: None

set_custom_attributes

def set_custom_attributes(key: str, value: Any) -> None
  • Description: Set custom attributes context in the current OpenTelemetry context
  • Parameters:
    • key (str): Custom attribute key
    • value (Any): Custom attribute value
  • Returns: None

set_custom_event

def set_custom_event(event_name: str, attributes: Any) -> None
  • Description: Set custom event in the current OpenTelemetry context
  • Parameters:
    • event_name (str): Name of the custom event
    • attributes (Any): Attributes associated with the event
  • Returns: None

add_conversation

def add_conversation(conversation_type: ConversationType, role: str, value: Any) -> None
  • Description: Append a conversation entry for the current active span and set/update the span attribute conversation as an array. If the conversation array already exists, the new entry is appended; otherwise, a new array is initialized.
  • Import:
from netra.session_manager import ConversationType
  • Parameters:
    • conversation_type (ConversationType): The conversation entry type. One of ConversationType.INPUT, or ConversationType.OUTPUT.
    • role (str): A non-empty role name to describe the message (e.g., “user”, “assistant”, “system”).
    • value (Any): The message content to record. Must not be None.
  • Returns: None
  • Note: If you are using one of the Netra instrumentations to trace the llm invocations in your application, then the messages that are associated with that invocation (User Message, System Message and Assistant Message) will be captured automatically without using this method. In such cases, using this method may result in duplication of messages in the dashboard.

SpanWrapper Class

set_prompt

def set_prompt(self, prompt: str) -> "SpanWrapper"
  • Description: Set the prompt used in the span
  • Parameters:
    • prompt (str): The prompt text
  • Returns: SpanWrapper instance (for method chaining)

set_negative_prompt

def set_negative_prompt(self, prompt: str) -> "SpanWrapper"
  • Description: Set the negative prompt used in the span
  • Parameters:
    • prompt (str): The negative prompt text
  • Returns: SpanWrapper instance (for method chaining)

set_model

def set_model(self, model: str) -> "SpanWrapper"
  • Description: Set the model name used in the span
  • Parameters:
    • model (str): Name of the model
  • Returns: SpanWrapper instance (for method chaining)

set_llm_system

def set_llm_system(self, system: str) -> "SpanWrapper"
  • Description: Set the LLM system used in the span
  • Parameters:
    • system (str): Name of the LLM system
  • Returns: SpanWrapper instance (for method chaining)

set_usage

def set_usage(self, usage_data: List[UsageModel]) -> "SpanWrapper"
  • Description: Set usage statistics for the span
  • Parameters:
    • usage_data (List[UsageModel]): List of usage statistics
  • Returns: SpanWrapper instance (for method chaining)

set_attribute

def set_attribute(self, key: str, value: str) -> "SpanWrapper"
  • Description: Set a custom attribute for the span
  • Parameters:
    • key (str): Attribute key
    • value (str): Attribute value
  • Returns: SpanWrapper instance (for method chaining)

add_event

def add_event(self, name: str, attributes: Dict[str, Any]) -> "SpanWrapper"
  • Description: Add an event to the span
  • Parameters:
    • name (str): Name of the event
    • attributes (Dict[str, Any]): Event attributes
  • Returns: SpanWrapper instance (for method chaining)

get_current_span

def get_current_span(self) -> Optional[trace.Span]
  • Description: Get the current OpenTelemetry span
  • Returns: Current span instance or None if not available

UsageModel Class

class UsageModel(BaseModel):
    model: str
    usage_type: str
    units_used: Optional[int] = None
    cost_in_usd: Optional[float] = None

ConversationType Enum

class ConversationType(str, Enum):
    INPUT = "input"
    OUTPUT = "output"
    SYSTEM = "system"
  • Description: Enumerates the allowed conversation entry types used by add_conversation.
  • Values:
    • ConversationType.INPUT → “input”: marks user/input content
    • ConversationType.OUTPUT → “output”: marks model/output content
    • ConversationType.SYSTEM → “system”: marks system or instruction content
  • Import:
from netra.models import ConversationType
I