node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Auto-injecting query comments

Open moltar opened this issue 3 years ago • 1 comments

It would be great to have support for injecting query comments into every query automatically, e.g. via config.

The use case is that these comments can then be used for analysis by tools like pganalyze.

See an example of a Ruby gem: https://github.com/basecamp/marginalia

I am thinking a config prop with string or factory type:

interface ConfigWithQueryComments {
  banner: string | () => string
}

Then:

const pool = new Pool({
  // ...

  banner: JSON.stringify({ app: 'foo', version: '1.2.3' })
})

moltar avatar May 24 '22 09:05 moltar

This will be huge help towards better observability - we can pass opentelemetry trace/span information to database engine that way, and be able to later correlate slow queries with traces by either using database logs or pgstatstatements.

  • some of commercical database vendors even automate this process, for example google cloud will automatically use such comment to produce correlated telemetry spans to aid investigation of slow queries in better context.

webervin avatar Jul 22 '24 06:07 webervin