Skip to main content

Sessions

Track user interactions across multiple traces.

Read sessions in the dashboard, or with an API key through the MCP server

What runs today: related traces are grouped into sessions and shown in the dashboard. Everything on this page about what a session is, and how to read one in the product, is current.

With an API key: the MCP server lists, filters and reads sessions with a Secret key. The REST API has no route for that. The REST API reference lists the routes that an API key can reach.

Sessions group related traces from a single user interaction or conversation.

What is a Session?

A session represents a continuous user interaction that may span multiple requests:

Session (session_id: sess-abc123)
├── Trace 1: "Hello, how can I help?"
├── Trace 2: "Search for Python tutorials"
├── Trace 3: "Show me the first result"
└── Trace 4: "Thanks, goodbye"

Creating Sessions

Automatic

Sessions are created automatically when you provide a session ID:

from risicare import session_context
 
async def handle_message(user_id: str, session_id: str, message: str):
    with session_context(session_id=session_id, user_id=user_id):
        response = await agent.process(message)
        return response

Put the session outside the run: open the session first, and the run (@agent, @trace or with risicare.trace(...)) inside it. The SDK writes the session on each span that starts inside the session, so a run span that starts before the session does not get it.

import risicare
from risicare import session_context
 
def handle_message(user_id: str, session_id: str, message: str):
    with session_context(session_id=session_id, user_id=user_id):  # 1. the session: outside
        with risicare.trace(name="support-turn"):                    # 2. the run: inside
            return agent.process(message)
import { agent, withSession } from 'risicare';
 
const answerTurn = agent({ name: 'support-agent' }, async (message: string) => answer(message));
 
export function handleMessage(userId: string, sessionId: string, message: string) {
  // 1. the session: outside. 2. the run: inside.
  return withSession({ sessionId, userId }, () => answerTurn(message));
}

See Session outside, run inside (Python) and in JavaScript.

Multi-Turn Conversations

Track conversation turns within a session:

with session_context(
    session_id="sess-abc123",
    user_id="user-456",
    turn_number=3,
    metadata={
        "source": "web",
        "device": "mobile",
        "locale": "en-US"
    }
):
    # All traces here belong to turn 3 of this session
    await process_request()

The turn_number parameter (default: 1) tracks which turn of the conversation a trace belongs to. Increment it for each user message in a multi-turn chat.

Session Attributes

AttributeTypeDescription
session_idstringUnique session identifier
user_idstringOptional user identifier
start_timetimestampStart time of the first span
end_timetimestampEnd time of the last span
duration_msnumberTotal session duration
trace_countnumberNumber of distinct trace IDs in the session
total_tokensnumberSum of all tokens
total_cost_usdnumberSum of all costs

Each time a session_context() block ends, or a @session call that has a session ID ends, the SDK sends a session.end marker span. If no span is active at that moment, the marker is a trace of its own. The dashboard does not show a trace that holds only the marker as a run: such a trace is not in the trace count and not in the error rate. The JavaScript SDK does the same for withSession() and session(). There is one marker span for each session call. With the session outside the run, the marker is a one-span trace of its own. It is never a failed trace (since Python 0.16.1 and npm 0.19.1): its status is ok, not error, and the outcome is in risicare.lifecycle.status (ok, error or cancelled). Through Python 0.16.0 and npm 0.19.0, a failed turn made the marker an error span too, so with the session outside the run one failed request read as two failed traces.

Session List View

The KPI strip above the list shows: Total Sessions, Unclosed, Success Rate, Avg Duration (with traces/session), LLM Calls (with tokens), and Total Cost.

View all sessions with:

ColumnDescription
Session IDClick to view details
User IDUser identifier, when one is set
Traces, spans, LLM calls, agentsCounts for the session
DurationTotal session length
CostTotal USD cost
Start timeWhen the session started

Session Detail View

The session page shows the KPI cards Duration, Traces, Tokens, Cost, Success Rate and Operations, and the tabs Span Waterfall, Timeline, Agent Messages (when the session has agent messages) and Raw Data.

Filtering Sessions

The Sessions page has a time range menu (it starts at Last 24 hours; the presets are Last hour, Last 24 hours, Last 7 days and Last 30 days) and a filter bar. The filter bar uses the same query language as the trace list — see Filtering and Search. It takes the same keys except trace, root and probes, and it takes no free text. It adds score.<name> for session scores, for example score.resolved:true. The list shows 50 sessions at a time and has a Next page button. The columns Release and Scores are off by default.

The REST API has no route that reads or filters sessions with an API key. The MCP server does, with a Secret key: its tool list_sessions takes a filter.

Session Continuity

Traces are grouped into a session purely by their session_id — reuse the same ID and the traces belong to the same session, no matter how much time passes between them. There is no inactivity timer; sessions are not auto-closed.

# First interaction
with session_context(session_id="sess-123"):
    await process("Hello")
 
# Any time later - same session, because the session_id matches
with session_context(session_id="sess-123"):
    await process("I have a follow-up question")

Privacy Considerations

User ID Hashing

For privacy, hash user IDs before sending:

import hashlib
 
def hash_user_id(user_id: str) -> str:
    return hashlib.sha256(user_id.encode()).hexdigest()[:16]
 
with session_context(
    session_id=session_id,
    user_id=hash_user_id(real_user_id)
):
    handle_request()

Next Steps