Users

Tracking user info in your traces for observability

Overview

You can track user interactions with your LLM app by setting the user_id in a trace. This allows you to track things such as how much tokens each user is costing you, who interacted with your LLM app the most, etc.

Set Users At Runtime

You can use the update_current_trace function to set the user_id within traces:

main.py
1from deepeval.tracing import observe, update_current_trace
2from openai import OpenAI
3
4client = OpenAI()
5
6@observe()
7def llm_app(query: str):
8 res = client.chat.completions.create(
9 model="gpt-4o",
10 messages=[{"role": "user", "content": query}]
11 ).choices[0].message.content
12
13 update_current_trace(user_id="your-user-id")
14 return res
15
16llm_app("Write me a poem.")

The user_id can be any string, including the actual IDs of customers in your own database, or even their email addresses. Everything will be viewable and searched in the UI.