---
title: set_transaction_name (Python agent API)
source: https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/settransactionname-python-agent-api
---

## Syntax

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

Sets the name of the current transaction.

## Description

This call sets the name of the current transaction.

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

```py
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).

## Parameters

| Parameter        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` _string_  | Required. Desired name for the current transaction. See the [description](#description) for an example of setting the name.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `group` _string_ | Optional. The `group` represents the naming structure for the `name` parameter, which is used to set the [transaction type](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/transactions-page#tx_functions) in the UI. See the [description](#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](#description) for more on using this.                                                                                                                                                                                                                           |
| `priority` _int_ | 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: ````py 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

None.

## Examples

### Using name and group parameters [#name-group-example]

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

```py
name = '%s/%s' % (controller, function) 
group = 'Python/WebFramework/Controller'

newrelic.agent.set_transaction_name(name, group)
```

### Setting name using current_transaction [#current-txn-example]

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

```py
transaction = newrelic.agent.current_transaction()
new_transaction_name = transaction.name
newrelic.agent.set_transaction_name(new_transaction_name)
```
