APM not collecting data for NodeJS applications which trigger services inside child processes. But correctly monitor in NodeJS express apps

Hi,
I'am using elastic APM to monitor some of the applications build using node. The APM correctly monitor NodeJS apps using express framework. But it is not monitoring some applications which are running services inside NodeJS child processes.

Kibana version:7.6.1

Elasticsearch version: :7.6.1

APM Server version: 7.6.1

APM Agent language and version:3.5.0 , NodeJS

Do you just want to record a span for the duration of the child process, or do you also want to record what goes on inside the child process?

The Node.js APM Agent does not automatically monitor child processes. To monitor what goes on inside a child process with you simply treat it as a regular process - i.e. start the agent again in each child process. You can optionally give each child process its own serviceName to distinguish them from each other.

Inside the child process. I'am triggering the services like redis, cassandra,mqtt, axios http. etc. I need to monitor them automatically. It is correctly working in express app. I shall try monitoring the child process seperately.

Ok, then the starting the agent in each child worker should do the trick. If you want to make use of distributed tracing across processes (that is, linking the transaction created in a child process as being a child of the span that caused the child process to start in the parent process), you need to pass a context object from the parent process to the child process. For more info on how to do this, see the Custom Protocols section in our Distributed Tracing documentation (in this case you can think of a child process as a custom protocol).

I have tried starting the APM agent in each child process. It still doesn't work. Since the application is not a supported framework by NodeJS APM . I think the only way is to use custom spans and transactions. I can see the spans for cassandra and redis are identified when custom transaction is used in the applications. Do we have any upcoming plans to support more frameworks and custom nodejs apps.?

The agent will technically still see your database calls in your child processes and try to create spans for each of them, but if it doesn't have a parent transaction to associate the spans with, it will just drop them.

Normally a transaction is started automatically by the agent if it detects an incoming HTTP request. In cases where the work your application is doing isn't based on incoming HTTP requests (as it sounds like is the case with your child processes), you just need to help the agent along by manually starting and ending transactions inside the child processes where it makes sense for you.

You can read more about this in the Custom Transactions documentation.

I hope this helps you :slight_smile:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.