Skip to main content

Netra Class

init

  • 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

  • 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 key
    • value (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 event
    • attributes (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 the conversation array already exists, the new entry is appended; otherwise, a new array is initialized.
  • Import:
  • 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

  • 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 key
    • value (str): Attribute value
  • Returns: SpanWrapper instance (for method chaining)

add_event

  • 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

  • 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 content
    • ConversationType.OUTPUT → “output”: marks model/output content
    • ConversationType.SYSTEM → “system”: marks system or instruction content
  • Import: