Attach User IDs to Traces
Learn how to attach user ids to traces in Langtrace. You can use the withAdditionalAttributes
or inject_additional_attributes
function to pass user ids. This can inturn be used within Langtrace for filtering and grouping traces.
You can attach user ids to traces in Langtrace by simply wrapping your code with the withAdditionalAttributes
for typescript or inject_additional_attributes
function for python. This will add the specified attributes to the trace spans. Make sure to pass the user id as a key-value pair to the function.
The key should be user_id
and the value should be the user id. User ids should be unique for each user.
DO NOT USE this the Python decorator - with_additional_attributes
. It will be
deprecated soon. Please use inject_additional_attributes
function instead.
Now, you can filter and group traces based on the user id. This can be useful for debugging and monitoring purposes.