User Tracking
Introduction
User tracking allows grouping and visualization of user-related traces, interactions, metrics, and costs. It also enables detection of user interaction outliers and other events.
Integration
See Quick Start guide on how to install and configure Graphsignal tracer.
Python
Set a session identifier as user_id
tag for every request, e.g. in a request handler. This will set a Python contextvar
and will be picked up by all traces of the current context. You can additionally set user_name
and user_email
tags.
graphsignal.set_context_tag('user_id', my_user_id)
You can also set tags directly, when tracing manually:
with graphsignal.trace('generate', tags=dict(user_id=my_user_id)):
...
OpenAI (Python)
Set a user_id
tag in request, call or run context. You can additionally set user_name
and user_email
tags.
graphsignal.set_context_tag('user_id', my_user_id)
Alternatively, a more reliable way to set user_id
and other tags is passing tags
in extra_headers
argument as comma-separated key-value pairs.
client = OpenAI()
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{'role': 'user', 'content': 'Tell me a joke'}],
extra_headers: {
'Graphsignal-Tags': f'user_id={my_user_id}'
})
LangChain (Python)
In case of automatic integration, set a user_id
tag in request, call or run context. You can additionally set user_name
and user_email
tags.
graphsignal.set_context_tag('user_id', my_user_id)
Alternatively, a more reliable way to set user_id
and other tags is passing tags
dictionary to callback constructor.
from graphsignal.callbacks.langchain import GraphsignalCallbackHandler, GraphsignalAsyncCallbackHandler
chat = ChatOpenAI(
callbacks=[GraphsignalCallbackHandler(tags=dict(user_id=my_user_id))])
CLI
If you are running a single process per session and added Graphsignal at command line, you can set the user_id
tag in an environment variable. You can additionally set user_name
and user_email
tags.
env GRAPHSIGNAL_TAGS="user_id=123" python -m graphsignal <script>