Update your Python SDK to version 2.0 for enhanced stability and easier integration. Learn more

Automatically Tracking Users

If your LLM provider supports passing End User IDs, Baserun will automatically collect the user ID and track user activity.

Please note that sending identifying information about your users, such as username or email address, to 3rd party services is not recommended. Instead, you can e.g. use hash function to avoid that, which we reflect in code examples below.

Sessions

A Session is a collection of LLM calls that are related to a long-term user interaction. A session can be started, resumed, and ended at any time and may contain many traces.

User Sessions are used to group traces together in the Users and Sessions monitoring pages.

For the Use cases of a chat bot, a Session may be the entire conversation. For an agent, a Session may encompass a single task execution. The scope of the session is specific to your application and what is most useful for you.

Adding Sessions

If you’re building a system where user interactions happen in a sequence (e.g. a chat bot) you’ll find it useful to group these interactions into a single session. The (with_session) context manager in Baserun allows you to do just that. By providing a user identifier, you can create a new session. By providing a session ID you can continue an existing session. This allows you to group all related traces under either the User or Session, making it easier to debug or analyze the user’s journey through your application.

Create a new session

Continuing an existing session

Using the Session ID that was collected when the session was started you can then resume that session by providing the session ID.

Full example

Providing a user identifier (the value is up to you) will allow you to group traces in the Users and Sessions monitoring pages.