1. Installation & Setup
Install Atatus Node.js package.
copynpm i atatus-nodejs@3.0.1-beta.4
Require Atatus in your Node.js app and invoke start with your License key and App name:
copyvar atatus = require("atatus-nodejs"); atatus.start({ licenseKey: "lic_apm_************", appName: "dev-api", tracing: true });
2. Pass Traceparent In Queue Message
To link an external Redis job API with the current trace context, you need to include the traceparent
value in the job message.
In below example, we are passing the traceparent
in the job message so that the child jobs can inherit the tracing context.
// server.js
var atatus = require("atatus-nodejs");
redisSub.on('message', async (channel, message) => {
try {
const traceparent = atatus.currentTransaction.traceparent;
const message = { jobType: 'processData', payload: { data: 'some_data' }, traceparent: traceparent };
const job = await queue.createJob({ data: 'some_data' }).save();
// your code here
} catch (e) {
}
})
3. Get & Set Traceparent in Background Transaction
On the worker server, you'll need to retrieve the traceparent
value from the incoming job message and use it to link the child job to the parent trace. This will allow you to trace the job across systems.
In this example, we are creating a new background transaction that is linked to the traceparent
from the incoming message. This ensures that tracing data is consistently propagated across your system, allowing you to track job processing in the context of the overall trace.
// worker.js
var atatus = require("atatus-nodejs");
redisSub.on('message', async (channel, message) => {
try {
const parsedMessage = JSON.parse(message);
if (parsedMessage.jobType === 'processData') {
const traceparent = parsedMessage.traceparent;
let trans;
trans = atatus.startBackgroundTransaction('Job Processing lat', {
childOf: traceparent || null
});
let job = await queue.createJob(parsedMessage.payload);
await job.save();
console.log(`Job added to Bee-Queue with ID: ${job.id}`);
if (trans) {
trans.end();
}
}
} catch () {
}
})