Syntax
newrelic.agent.set_user_id(user_id)A standardized way to identify an end user on Transaction events with the set_user_id method.
This method is used for user tracking, which is a standardized way to identify an end user on Transaction events.
Requirements
Python agent version 8.8.0 or higher.
Description
This call is used within the context of a transaction to attach an end user to a particular transaction or error event. This allows the customer to gain insight about a particular end user.
Parameters
Parameter  | Description  | 
|---|---|
 string  | Required.  | 
Return values
None.
When successful, the API will add the user ID as an agent attribute.
When unsuccessful, the API will not add enduser.id as an agent attribute.  A failure may occur for several reasons:
- The current transaction is not enabled.
 - Nothing was provided as an input to the API.
 - Something was provided but it was not a string.
 
Example usage
Set user ID inside a background task
An example of using set_user_id inside a simple Flask app to set the user id of the transaction:
from flask import Flaskimport newrelic.agent
app = Flask("Flask Test App")
@app.route("/")def hello():    try:        newrelic.agent.set_user_id("my-user-id")        raise ValueError("Oh no!")    except:        newrelic.agent.notice_error()    return "Hello World!"
if __name__ == '__main__':    app.run()