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

# Session Tracking

> Track user sessions in Netra to group related AI interactions. Associate traces with session IDs to analyze multi-turn conversations and workflows.

Session tracking in Netra provides powerful capabilities for monitoring user interactions and application behavior. This section covers how to track sessions, add custom context, and record events within your application.

## Setting Up Session Tracking

Before you can start tracking sessions, initialize the Netra SDK:

<CodeGroup>
  ```python python theme={null}
  from netra import Netra
  from netra.instrumentation.instruments import InstrumentSet

  # Initialize with default settings
  Netra.init(app_name="Your application name")

  # Or with custom configuration
  api_key = "Your API key"
  headers = f"x-api-key={api_key}"
  Netra.init(
      app_name="Your application name",
      headers=headers,
      trace_content=True,
      environment="Your Application environment",
  	instruments={InstrumentSet.OPENAI}
  )
  ```
</CodeGroup>

## Session Identification

Set unique identifiers for your sessions:

<CodeGroup>
  ```python python theme={null}
  # Set session identification
  Netra.set_session_id("unique-session-id")
  Netra.set_user_id("user-123")
  Netra.set_tenant_id("tenant-456")
  ```
</CodeGroup>

## Custom Context Attributes

Add custom attributes to enrich your session data:

<CodeGroup>
  ```python python theme={null}
  # Add custom context attributes
  Netra.set_custom_attributes(key="customer_tier", value="premium")
  Netra.set_custom_attributes(key="region", value="us-east")
  Netra.set_custom_attributes(key="plan_type", value="enterprise")
  ```
</CodeGroup>

## Custom Events

Record important events in your application:

<CodeGroup>
  ```python python theme={null}
  # Record user feedback event
  Netra.set_custom_event(event_name="user_feedback", attributes={
      "rating": 5,
      "comment": "Great response!",
      "timestamp": "2024-01-15T10:30:00Z",
      "category": "positive"
  })

  # Record conversion event
  Netra.set_custom_event(event_name="conversion", attributes={
      "type": "subscription",
      "plan": "premium",
      "value": 99.99,
      "currency": "USD",
      "source": "website",
      "campaign": "spring_sale"
  })

  # Record error event
  Netra.set_custom_event(event_name="error_occurred", attributes={
      "error_type": "authentication",
      "error_message": "Invalid credentials",
      "severity": "high",
      "user_action": "login"
  })
  ```
</CodeGroup>
