If you can change the application then one option is to set application_name so that it contains API function name. This should happen before the first call in API function hits the database. After the API function finishes it should reset application_name.
Then you can enable logging of all queries and set the format to include application_name parameter. This way every query is logged and each log entry has an application name.
Several things to keep in mind:
1. logging everything may affect performance
2. application_name is 64 chars by default
In API function may invoke 10 queries. Ideally, I would like to know what queries are invoked by it and how long each took.
I’m using pg_stat_statement. I can see the API function statement, but how do I deterministically identify all queries invoked by it?
----------------
Thank you