Netra Class
init
- Description: Initialize the Netra SDK with configuration options
- Parameters:
app_name
(Optional[str]): Name of the application for tracingheaders
(Optional[str]): Headers for API requests (e.g., API keys)disable_batch
(Optional[bool]): Disable batch processing of spanstrace_content
(Optional[bool]): Enable tracing of contentresource_attributes
(Optional[Dict[str, Any]]): Additional resource attributesenvironment
(Optional[str]): Application environment (e.g., “production”, “development”)instruments
(Optional[Set[NetraInstruments]]): Set of instruments to enableblock_instruments
(Optional[Set[NetraInstruments]]): Set of instruments to blockenable_root_span
(Optional[bool]): Enable root span to trace the entire application in a single tracedebug_mode
(Optional[bool]): Enable debug mode to get application logsenable_scrubbing
(Optional[bool]): Enable scrubbing of sensitive datablocked_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
- 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
- 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
- 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
- Description: Set custom attributes context in the current OpenTelemetry context
- Parameters:
key
(str): Custom attribute keyvalue
(Any): Custom attribute value
- Returns: None
set_custom_event
- Description: Set custom event in the current OpenTelemetry context
- Parameters:
event_name
(str): Name of the custom eventattributes
(Any): Attributes associated with the event
- Returns: None
add_conversation
- Description: Append a conversation entry for the current active span and set/update the span attribute
conversation
as an array. If theconversation
array already exists, the new entry is appended; otherwise, a new array is initialized. - Import:
- Parameters:
conversation_type
(ConversationType): The conversation entry type. One ofConversationType.INPUT
, orConversationType.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 beNone
.
- 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
- Description: Set the prompt used in the span
- Parameters:
prompt
(str): The prompt text
- Returns: SpanWrapper instance (for method chaining)
set_negative_prompt
- Description: Set the negative prompt used in the span
- Parameters:
prompt
(str): The negative prompt text
- Returns: SpanWrapper instance (for method chaining)
set_model
- 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
- 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
- Description: Set usage statistics for the span
- Parameters:
usage_data
(List[UsageModel]): List of usage statistics
- Returns: SpanWrapper instance (for method chaining)
set_attribute
- Description: Set a custom attribute for the span
- Parameters:
key
(str): Attribute keyvalue
(str): Attribute value
- Returns: SpanWrapper instance (for method chaining)
add_event
- Description: Add an event to the span
- Parameters:
name
(str): Name of the eventattributes
(Dict[str, Any]): Event attributes
- Returns: SpanWrapper instance (for method chaining)
get_current_span
- Description: Get the current OpenTelemetry span
- Returns: Current span instance or None if not available
UsageModel Class
ConversationType Enum
-
Description: Enumerates the allowed conversation entry types used by
add_conversation
. -
Values:
ConversationType.INPUT
→ “input”: marks user/input contentConversationType.OUTPUT
→ “output”: marks model/output contentConversationType.SYSTEM
→ “system”: marks system or instruction content
- Import: