• EnglishEspañol日本語한국어Português
  • Log inStart now

set_transaction_name (Python agent API)


newrelic.agent.set_transaction_name(name, group=None, priority=None)

Sets the name of the current transaction.


This call sets the name of the current transaction.

Here's an example showing one way to implement the name and group parameters:

name = '%s/%s' % (controller, function)
group = 'Python/WebFramework/Controller'newrelic.agent.set_transaction_name(name, group)

The priority parameter can generally be ignored unless you are implementing custom instrumentation for a web framework where there may be multiple points where you want to set the name (such as middleware, view handlers, or error handlers).






Required. Desired name for the current transaction. See the description for an example of setting the name.



Optional. The group represents the naming structure for the name parameter, which is used to set the transaction type in the UI. See the description for an example of setting the group.

If not supplied, the group will default to the Function name in expectation that the name is of the form module:class.function or module:function and represents the name of the function being executed. If you are creating a custom group, we recommends you prefix it with Python/.

The naming structure used for naming the transaction. As this value is rendered as part of a URL, non-ASCII encoding should be avoided. Defaults to Function. See Description for more on using this.



Optional. The priority value is used to determine what name is given to a transaction. Higher numbers override lower numbers. The default value is None, meaning the transaction name overrides any existing value. If the priority is left as None, the new name always overrides any existing value. Here's an example of how priority works:

newrelic.agent.set_transaction_name('first', 'Python/CustomGroup')
# transaction name becomes 'first'.
newrelic.agent.set_transaction_name('second', 'Python/CustomGroup', priority=10)
# transaction name becomes 'second'. The priority becomes 10.
newrelic.agent.set_transaction_name('third', 'Python/CustomGroup', priority=5)
# transaction name is still 'second' because 5 < 10.
newrelic.agent.set_transaction_name('fourth', 'Python/CustomGroup', priority=15)
# transaction name becomes 'fourth' because 15 > 10. The priority becomes 15.
newrelic.agent.set_transaction_name('fifth', 'Python/CustomGroup')
# transaction name becomes 'fifth'. The priority remains 15.

Return values



Using name and group parameters

An example showing one way to implement the name and group parameters:

name = '%s/%s' % (controller, function)
group = 'Python/WebFramework/Controller'
newrelic.agent.set_transaction_name(name, group)

Setting name using current_transaction

An example of using current_transaction to set the current transaction name:

transaction = newrelic.agent.current_transaction()
new_transaction_name = transaction.name
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.