What is a Session?
A session is a grouping of related traces. For example, in a chatbot application, each conversation generates multiple traces — one for each human message and AI response. By organizing these related traces into a single session, you can easily view and analyze the full conversation flow between the human and the AI. Sessions allow you to track context across turns and understand how your application behaves over the course of an interaction.
Why are Sessions Important?
By grouping your traces into sessions, you can:- Find exactly where a conversation “breaks” or goes off the rails. This can help identify if a user becomes progressively more frustrated or if a chatbot is not helpful.
- Identify broader performance issues across sessions by running session-level evaluations.
- Construct custom metrics based on evals using
session.idoruser.idto find best/worst performingsessionsandusers.
Configure Sessions
Addingsession.id and/or user.id from an application enables back-and-forth interactions to be grouped.
Session and user IDs can be added to a span using auto instrumentation or manual instrumentation of Open Inference. Any LLM call within the context (the with block in the example below) will contain corresponding session.id or user.id as a span attribute. session.id and user.id must be a non-empty string.
When defining your instrumentation, you can pass the sessionID attribute as shown below.
- Python
- JS/TS
using_session
Context manager to add session ID to the current OpenTelemetry Context. OpenInference auto instrumentators will read this Context and pass the session ID as a span attribute, following the OpenInference semantic conventions. Its input, the session ID, must be a non-empty string.using_user
Context manager to add user ID to the current OpenTelemetry Context. OpenInference auto instrumentators will read this Context and pass the user ID as a span attribute, following the OpenInference semantic conventions. Its input, the user ID, must be a non-empty string.Additional Examples
- OpenAI
- Langchain
- Llama Index
- Bedrock
- Mistral AI
- DSPy
Requires
pip install openinference-instrumentation-openai