A standardized way to identify an end user on
Transaction events with the
This method is used for user tracking, which is a standardized way to identify an end user on
Python agent version 8.8.0 or higher.
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.
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.
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.agentapp = 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()