APM Agent not working with Nodejs

Guys, I'm trying to use APM in a NodeJS API I have, every environment is local using Docker.

The APM Server normally connects to the Kibana check, but the problem is that my Agent in this check returns the message "No data has been received from agents yet", even following the step-by-step that is informed.

My docker-compose.yaml looks like this: link in pastebin

In my Node application I put this code snippet to start at the top of the main file as it is informed in the documentation.

import apm from 'elastic-apm-node';

apm.start({
  serviceName: 'api',
  secretToken: '',
  serverUrl: 'http://host.docker.internal:8200',
  environment: 'development',
  active: true,
  logLevel: 'debug',
});

APM Server running

APM Agent not working

APP NodeJS running

I don't get error logs on the APM server

If I skip the Agent part and click on Load Kibana objects, my service appears available, and the data starts to be obtained when performing some request, but it is not 100% functional, because when an error occurs, I don't have the stack tracing, between other things, how do I succeed in this connection?

Hello @Mayderson_Santos. Thanks for the question.

Unfortunately, the current Elastic Node.js APM agent does not support automatically patching modules that use the import ... statement (ESM). There are two issues here:

  1. First, the way import works, all modules are loaded in a phase before the code that imported those modules runs. That means that in your example, import apm from 'elastic-apm-node'; loads the APM agent module, and any imports lower down (e.g., import http from 'http') will load those modules before the apm.start(...) is executed. This APM agent document describes how to use import 'elastic-apm-node/start' to solve this issue. (However that doc is misleading in that it implies that ESM is then fully supported.)
  2. The second issue is that currently the APM agent cannot hook into subsequent import statements, (e.g. import http from 'http'), so it is unable to do any automatic tracing. The APM agent's manual instrumentations still work, e.g. apm.startTransaction(...), but that is too limited.

We hope to work on ESM support for the Node.js APM agent, however, I don't have a timeline for that. Here is an initial issue to look into clarifying our docs (also around similar surprises when using TypeScript and/or bundlers like webpack): improve agent docs for use with TypeScript, bundlers, and perhaps ESM · Issue #1967 · elastic/apm-agent-nodejs · GitHub

Thank you for the answer, I even saw steps in the documentation for Babel/ES Module etc. I did them without success.

But I also tried to start a project from scratch, as attached in the last image I posted in the thread, with only JavaScript and 2 dependencies, which is express and apm-agent-nodejs itself, the code practically the same as copied in the documentation , but I keep having the same problem, it just returns "No data has been received from agents yet".

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