What are Sessions?
A session represents a logical grouping of traces that belong together, such as:- Multi-turn conversations with a chatbot
- User sessions across multiple requests
- Related operations in a workflow
- A/B test variants for comparison
Why Use Sessions?
Sessions help you:- Track conversations across multiple LLM interactions
- Analyze user behavior over time
- Debug issues by viewing all related traces together
- Calculate metrics across multiple operations
- Group experiments for comparison
Setting Session IDs
Using using_session Context Manager
The recommended way to set session IDs:
using_session context will have the same session ID in their metadata.
Manual Session Metadata
You can also set session metadata manually on spans:Session ID Strategies
- User-Based
- Conversation-Based
- Time-Based
- Workflow-Based
Real-World Example: Chat Application
Here’s a complete example of using sessions in a chat application:Session Metadata
Enrich sessions with additional metadata:Filtering by Session
In Phoenix UI
- Open Phoenix at http://localhost:6006
- Navigate to the Traces view
- Use the search bar:
metadata.session_id:"your-session-id" - View all traces for that session together
Using Phoenix Client
Session Analytics
Analyze sessions to understand user behavior:Session Best Practices
Sessions vs Projects
| Feature | Sessions | Projects |
|---|---|---|
| Scope | Groups related traces | Isolates entire applications |
| Duration | Short-lived (minutes to hours) | Long-lived (entire app lifetime) |
| Use Case | User conversations, workflows | Applications, environments |
| Filtering | Via metadata search | Top-level selector |
| Isolation | Logical grouping only | Complete data isolation |
Next Steps
Annotations
Add feedback and evaluations to traces
Cost Tracking
Monitor LLM costs across sessions