No, typically you would surround the contents. Something like this:
client.begin_transaction('request')
try:
response = publish(request, module_name, after_list, debug=debug)
except Exception:
elasticapm.capture_exception(handled=False)
raise
finally:
client.end_transaction(request.method + " " + request.get('PATH_INFO'), response.status)