> ## Documentation Index
> Fetch the complete documentation index at: https://keyvalue.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Welcome to the home of your new documentation

## Netra Class

### init

```python python theme={null}
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. Supports wildcard matching.
* **Returns**: None

### set\_session\_id

```python python theme={null}
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

```python theme={null}
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

```python theme={null}
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

```python theme={null}
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

```python theme={null}
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

```python python theme={null}
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**:

```python theme={null}
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

```python python theme={null}
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

```python python theme={null}
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

```python python theme={null}
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

```python python theme={null}
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

```python python theme={null}
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

```python python theme={null}
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

```python python theme={null}
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

```python python theme={null}
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

```python python theme={null}
class UsageModel(BaseModel):
    model: str
    usage_type: str
    units_used: Optional[int] = None
    cost_in_usd: Optional[float] = None
```

## ConversationType Enum

```python python theme={null}
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**:

```python theme={null}
from netra.models import ConversationType
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.