-
Notifications
You must be signed in to change notification settings - Fork 239
Open
Labels
Description
I am using bullmq as a queue on Node, and I have integrated it into apm using a custom method, but I have encountered some issues. Here is my code.
const apm = require('elastic-apm-node/start');
const shimmer = require('elastic-apm-node/lib/instrumentation/shimmer');
const { Worker } = require('bullmq');
shimmer.wrap(Worker.prototype, 'callProcessJob', function (original) {
return async function callProcessJob(job, token) {
const transName = `${job.queueName}[${job.name}]`;
const trans = apm.startTransaction(transName, 'queue');
apm.setCustomContext(job.toJSON());
try {
trans.outcome = 'success';
return await original.call(this, job, token);
} catch (e) {
trans.result = e.message;
trans.outcome = 'failure';
apm.captureError(e);
throw e;
} finally {
trans.end();
}
};
});Although I have called the trans.end() method, the apm still collected the methods called in bullmq to redis, which should not have happened. What should I do to avoid this situation?
Thank you for your help.