Group related spans into sessions for better organization and analysis
Sessions provide a powerful way to group related spans together, making it easier to track and analyze complex workflows, user interactions, or multi-step processes. This guide covers everything you need to know about working with sessions.For complete API documentation, see the Python SDK Reference or TypeScript SDK Reference.
The simplest way to create a session is by providing a session ID:
Copy
Ask AI
import uuidimport zeroeval as ze# Generate a unique session IDsession_id = str(uuid.uuid4())@ze.span(name="process_request", session=session_id)def process_request(data): # This span belongs to the session return transform_data(data)
For better organization in the ZeroEval dashboard, you can provide both an ID and a descriptive name:
Copy
Ask AI
@ze.span( name="user_interaction", session={ "id": session_id, "name": "Customer Support Chat - User #12345" })def handle_support_chat(user_id, message): # Process the support request return generate_response(message)
Child spans automatically inherit the session from their parent span:
Copy
Ask AI
session_info = { "id": str(uuid.uuid4()), "name": "Order Processing Pipeline"}@ze.span(name="process_order", session=session_info)def process_order(order_id): # These nested calls automatically belong to the same session validate_order(order_id) charge_payment(order_id) fulfill_order(order_id)@ze.span(name="validate_order")def validate_order(order_id): # Automatically part of the parent's session return check_inventory(order_id)@ze.span(name="charge_payment")def charge_payment(order_id): # Also inherits the session return process_payment(order_id)