Closed apletnev closed 1 month ago
Thanks for reporting the issue. I will look into.
Can you please provide some more details on how to did execute the query? Was it with query on a client object, or a pool object or as part of a tasks or transaction?
I think I found the issue. The context is only set if a query is executed inside a task/transaction. Unfortunately this is not reflected in the code of pg-promise but only mentioned in the documentation. I will make an update of the exporter to reflect this condition.
Can you by change add an example where the problem occurs as I somehow cannot reproduce it until now. I also checked the pg-promise code and this situation should actually never occur. Hence it would be great if you add more context, how you execute the query, which parameters are used etc. Thanks in advance
Sure, here is my code
const METRICS_ID = process.env.METRICS_ID || 'node-api';
const METRICS_TYPE = process.env.METRICS_TYPE || 'api';
const initOptions = {
capSQL: true,
query(e) {
logger.debug(e.query);
}
};
const CUSTOM_Labels = {
id: METRICS_ID,
type: METRICS_TYPE
};
const registry = new prometheus.Registry();
const api_eventpipe_clients = new prometheus.Gauge({
name: 'api_eventpipe_clients',
help: 'Eventpipe clients count',
registers: [registry],
labelNames: [...Object.keys(CUSTOM_Labels)]
});
const pgp = require('pg-promise')(initOptions);
const pgdb = pgp({
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASS,
allowExitOnIdle: true
});
pgPromiseExporter.monitorPgPromise(pgdb, initOptions, registry, {defaultLabels: CUSTOM_Labels});
// it fails here
const datasources = await store.pgdb.any('select * from s_get_drivertplls(${params})', { params: Object.assign({}, { sysuser: { id: 0 } }) });
Thanks for providing the example. It really help to narrow down the condition when this happens. I have partially fixed it already plan to do some more cleanup/test coverage. Will release a new version soon.
A fix is available with version 2.1.1. @apletnev: Thanks again for your support.
Environment:
The code fails on the onReceive method when trying to get event.ctx.ctx.success.
Stacktrace: