DocsObservabilityFeaturesUser Tracking

User Tracking

The Users view provides an overview of all users. It also offers an in-depth look into individual users.

It’s easy to map data in Langfuse to individual users. Just propagate the userId attribute across observations. This can be a username, email, or any other unique identifier. The userId is optional, but using it helps you get more from Langfuse aggregating metrics such as LLM usage cost by userId. See the integration docs to learn more.

When using the @observe() decorator:

from langfuse import observe, propagate_attributes
 
@observe()
def process_user_request(user_query):
    # Propagate user_id to all child observations
    with propagate_attributes(user_id="user_12345"):
        # All nested observations automatically inherit user_id
        result = process_query(user_query)
        return result

When creating observations directly:

from langfuse import get_client, propagate_attributes
 
langfuse = get_client()
 
with langfuse.start_as_current_span(
    name="process-user-request"
) as root_span:
    # Propagate user_id to all child observations
    with propagate_attributes(user_id="user_12345"):
        # All observations created here automatically have user_id
        with root_span.start_as_current_generation(
            name="generate-response",
            model="gpt-4o"
        ) as gen:
            # This observation automatically has user_id
            pass
Note on Attribute Propagation
We use Attribute Propagation to propagate `userId` across all observations of a trace. We will use all observations with `userId` to create `userId`-level metrics. Please consider the following when using Attribute Propagation:
  • Values must be strings ≤200 characters
  • Call early in your trace to ensure all observations are covered. This way you make sure that all Metrics in Langfuse are accurate.
  • Invalid values are dropped with a warning

View all users

The user list provides an overview of all users that have been tracked by Langfuse. It makes it simple to segment by overall token usage, number of traces, and user feedback.

User List

Individual user view

The individual user view provides an in-depth look into a single user. Explore aggregated metrics or view all traces and feedback for a user.

You can deep link to this view via the following URL format: https://<hostname>/project/{projectId}/users/{userId}

GitHub Discussions

Was this page helpful?