elastic / elastic/apm-agent-nodejs

[Question] Support bullmq

Open
#4,037 8 comments 0 reactions 0 assignees View on GitHub
community
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

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.
```javascript
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?

image

Thank you for your help.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.