I would like to implement my custom logging via a ...
# off-topic
c
I would like to implement my custom logging via a private logs table (e.g. I can then insert records inside that logs table during the exection of triggers to get visibility into trigger executions).
In addition to a log message, I would like to associate some metadata to the log: some JWT attributes (e.g. the sub), the session id and transaction id. The reason I want a session and/or transaction id is to be able to identify that a set of logs which were generated during for the same logical operation. For example, if a trigger invokes several other functions and each of those functions logs something, I would like to be able to identify that the logs are from the same logical operation.
With all that in mind, I have 4 questions: - If we focus on the high-level goal described above, does this approach seem reasonable or is there something I am missing? - Do triggers get invoked with the same JWT as the JWT of the operation which invoked the trigger? If NOT, is there any way to link the trigger to the user which started the invoking operation? - Given that the supabase client goes through PostgREST - how does PostgREST handle sessions? Is it one session per user or is it more complex than that? - If I understand correctly, read-only operataions do NOT have a transaction id (since they don't need a transaction) - is there something similar I can use to identify the sub-operations of such operations?
btw, I plan to use pg_backend_pid() and pg_current_xact_id_if_assigned() in order to retrieve the current session and transaction id