neumino / rethinkdbdash

An advanced Node.js driver for RethinkDB with a connection pool, support for streams etc.
MIT License
848 stars 109 forks source link

rethinkdb-inspector #361

Closed mxstbr closed 6 years ago

mxstbr commented 6 years ago

I build a tiny module to figure out which queries are run and how long they take to complete: https://github.com/withspectrum/rethinkdb-inspector

My approach to figuring that out is to monkey-patch Term.prototype.run, simplified this is what it boils down to:

// Store the original .run()
const run = r._Term.prototype.run;

r._Term.prototype.run = function inspectRun(...args) {
  // ...log the query...
  return run.call(this, ...args).then(result => {
    // ...log how much time the query took...
    return result;
  })
}

Question: Is r._Term pretty future-proof? If not, is this something that could live in core? I know it's been very useful for us!

neumino commented 6 years ago

Hum, _Term is a private property, so there's no guarantee to keep it later. It's kind of a low level thing that shouldn't change though...