For general information on how the Python agent API calls relate to each other, see the API guide.

Returns an object corresponding to the current transaction.


Some Python agent API calls require you to pass in an object representing the current transaction. (For example, FunctionTrace requires passing in the current transaction object.) Use current_transaction to retrieve this object. It will return None if there is no active transaction.


Parameter Description



Optional. Default is True, meaning it will only return active transactions. If set to False, the call is capable of returning a transaction that has ended or stopped (for example, if end_of_transaction was used).

Return value(s)

Returns a transaction object corresponding to current transaction; this object is required by some other Python agent API calls. Returns None if there is no active transaction.


Running function trace on current transaction

An example of using current_transaction in creating a function trace:

def main():
    transaction = newrelic.agent.current_transaction()

    if not transaction:

    with newrelic.agent.FunctionTrace(transaction, '__main__:func'):
        return func()

For more help

Recommendations for learning more: