Add diagnostics_channel TracingChannel support

Closed
LO
6mo ago
+557-11

This PR introduces tracing channels support to pg-pool and pg querying methods as discussed in #3619

I haven't yet run a benchmark, but without active tracing or subscribers the overhead is non-existent so existing users shouldn't be affected. The overhead would come from the consumers of the diag channels published here which is done anyways via monkey patching.

I added the following channels:

ChannelTypePackageDescription
pg:queryTracingChannelpgQuery lifecycle (start, end, error with async context)
pg:connectionTracingChannelpgClient connection lifecycle
pg:pool:connectTracingChannelpg-poolPool connection acquisition lifecycle
pg:pool:releaseChannelpg-poolClient released back to pool
pg:pool:removeChannelpg-poolClient removed from pool

I understand there may be hesitation given that AI tooling was used in the implementation. To be clear, this isn't a drive-by contribution. I designed the channel layout, wrote the proposal document, and iterated through multiple rounds to handle real edge cases (Node 18 compat, preserving custom Promise types, hasSubscribers guards). The AI assisted with the code, but the approach and decisions are mine.

This is part of a broader initiative to bring TracingChannel support to the most widely used Node.js database and cache libraries. The same pattern has already been merged and shipped in:

I have been directly involved in those prior implementations and I'm happy to own this through to release, address any feedback, and provide whatever support is needed. Would love to hear your thoughts.