appmetrics icon indicating copy to clipboard operation
appmetrics copied to clipboard

'postgres' event not working when used with pg-promise module

Open hotam-singh opened this issue 6 years ago • 5 comments

Hi, I am using node.js version 8.4.0 and pg-promise version 5.5.6

'postgres' event not called in my application. Please help me out to fix this issue.

my email is [email protected]

hotam-singh avatar Oct 26 '17 06:10 hotam-singh

Hi @hotam-singh , do you have a simple test case that replicates the problem that we can work on?

mattcolegate avatar Oct 26 '17 08:10 mattcolegate

Hi @mattcolegate , I don't have sample test case. It is a huge code to make a test case and of course will take time but I had added following code in my app.js file

var appmetrics = require('appmetrics'); var monitoring = appmetrics.monitor();

monitoring.on('initialized', function (env) { console.log(chalk.green('initialized') + ' : ' + chalk.yellow('[ETPCoinMetric] init')); });

monitoring.on('socketio', function(data) { console.log(chalk.green('socketio') + ' : ' + chalk.yellow('[ETPCoinMetric] duration='+data.duration+' ms url='+data.url+' method='+data.method+' event='+data.event)); });

monitoring.on('http', function (data) { console.log(chalk.green('http') + ' : ' +chalk.yellow('[ETPCoinMetric] duration='+data.duration+' ms url='+data.url)); });

monitoring.on('postgres', function(data) { console.log("SQL Query: "+data.query); console.log("Duration: "+data.duration); //console.log('event postgres : ' + chalk.yellow('[ETPCoinMetric] duration='+data.duration+' ms url='+data.url)); });

All events triggered successfully instead of 'postgres'. No log is being printed for 'postgres'

hotam-singh avatar Oct 26 '17 10:10 hotam-singh

Please let me know what I am missing?

hotam-singh avatar Oct 27 '17 07:10 hotam-singh

@hotam-singh without seeing all your code this is a hard one to diagnose, and I don't really have the time to investigate what pg-promise is and construct my own test case, particularly as you've already stated it's a huge piece of code to make one. The code you've posted so far looks good, and you've stated that you've seen all the other events you are monitoring. As a wild stab in the dark, are you making sure that your require('appmetrics') statement appears as the first line of your application? Do you require('pg') before you require('appmetrics')?

mattcolegate avatar Oct 30 '17 10:10 mattcolegate

See https://github.com/RuntimeTools/appmetrics/issues/151. Appmetrics doesn't necessarily work with npm modules that wrap supported modules, depending on how the require statement is written in the wrapper module. If it's not working for you and you've got the require statements in the right order like @mattcolegate suggested then unfortunately it probably doesn't work. We know that other modules that wrap pg defintely don't work.

Appmetrics is open source and we're open to pull requests if someone is interested in adding support for one of these wrapper modules like pg-promise.

sjanuary avatar Oct 30 '17 15:10 sjanuary