Custom Business Transactions

You can use the start_bt() and end_bt() methods to surround the code that you want to monitor as a custom business transaction.

Or you can use the "bt" context manager. Consider using the bt context manager where you start and end the business transaction in the same code. For example, where you can wrap the whole business transaction in a with statement.

For example, given the code:
 setup()
 do_work()
 teardown()

you want to report do_work() as a business transaction.

Use start_bt() and end_bt()

This example uses start_bt() and end_bt() to create a business transaction named do_work.
from appdynamics.agent import api as appd        
setup()
 
bt_handle = appd.start_bt('do work')
try:
    do_work()
except Exception as exc:
    raise
finally:
    appd.end_bt(bt_handle, exc)

teardown()

Use bt context manager

If the business transaction starts and ends in the same context, you can use the bt context manager instead. This is simpler:
setup()

with bt('do work'):
    do_work()

teardown()