brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.36k stars 1.23k forks source link

Auto-injecting query comments #2745

Open moltar opened 2 years ago

moltar commented 2 years ago

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' })
})
webervin commented 4 months ago

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.