Kibana version: Latest
Elasticsearch version: Latest
APM Server version: Latest
APM Agent language and version: Node latest
Original install method (e.g. download page, yum, deb, from source, etc.) and version: pnpm
Fresh install or upgraded from other version? upgraded
Is there anything special in your setup? No
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
I hope this code is clear enough. Basically my issue is that I got nothing when using apm client in a node child process. I must be missing something but no idea what at this point.
This is the code I init with a simple node cmd:
const { elasticApm } = require('@outmind/apm');
const cp = require('child_process');
const apmconf = {
environment: 'staging',
secretToken: 'xxx
serverUrl: 'https://xxx:443',
serviceName: 'deepsyncengine',
serviceVersion: '1.0.0',
active: true,
logLevel: 'trace',
};
elasticApm.start(apmconf);
const getHours = () => {
const a = new Date();
return `${a.getHours()}:${a.getMinutes()}:${a.getSeconds()}`;
};
console.log('elasticApm is started => ', elasticApm.isStarted());
const service = async () => {
const h = getHours();
console.log('service is started', h);
const transaction = elasticApm.startTransaction(`TEST-${h} Transaction started in my test`);
console.log('elasticApm current transaction ==>', elasticApm.currentTraceparent);
const span = elasticApm.startSpan('THIS IS A SPAN START');
await new Promise((res, rej) => setTimeout(() => res(), 1500));
span.end();
const childProcess = cp.fork('./src/file-parser/pamworker.js', {});
childProcess.send({
parentTransaction: elasticApm.currentTraceparent,
// apmClient: elasticApm,
});
childProcess.on('error', (e) => {
console.log('error in childprocess ==>', e);
});
childProcess.on('exit', (code, signal) => {
console.log('childprocess exit ==>', code, signal);
transaction.end('success');
console.log('transaction is ended', transaction.ended);
console.log('service is endend');
});
};
service();
This is the code of the worker in child process :
const { elasticApm, makeApmConfig } = require('@outmind/apm');
const apmconf = {
environment: 'staging',
secretToken: 'xxx',
serverUrl: 'https://xxx:443',
serviceName: 'deepsyncengine',
serviceVersion: '1.0.0',
active: true,
logLevel: 'trace',
};
const getHours = () => {
const a = new Date();
return `${a.getHours()}:${a.getMinutes()}:${a.getSeconds()}`;
};
process.on('message', async (data) => {
elasticApm.start(apmconf);
const d = getHours();
console.log('message in worker data ==>', data, d);
console.log('apm started in worker ==>', elasticApm.isStarted());
const orphanTrans = elasticApm.startTransaction(`Worker orphanTrans ${d}`);
// console.log('have a look at span worker ==>', orphanTrans);
await new Promise((res, rej) => setTimeout(() => res(), 2000));
orphanTrans.end('success');
console.log('orphan trans ended');
const transaction = elasticApm.startTransaction('Worker transaction', {
childOf: data.parentTransaction,
});
console.log('have a look at transaction worker ==>', transaction.ended);
await new Promise((res, rej) => setTimeout(() => res(), 2000));
transaction.end('success');
console.log('transaction worker ended', transaction.ended);
process.exit(0);
});
Just dummy code but it proves what I want to do.
I got all the log.
I can see my transaction in the first file, including the span I attach to it.
I can NOT see any event sent from the worker. Neither the orphan transaction nor the childOf.
No error. The strack trace looks fine to me (very long but I can attach it to this post).
I'd appreciate any help on this !
Thanks all.
P.S: I did read this: APM not collecting data for NodeJS applications which trigger services inside child processes. But correctly monitor in NodeJS express apps