# APM Agent not working with Nodejs

**URL:** <https://discuss.elastic.co/t/apm-agent-not-working-with-nodejs/295638>\
**Category:** APM\
**Tags:** docker, fleet, nodejs\
**Created:** [January 27, 2022, 10:49pm UTC](https://discuss.elastic.co/t/apm-agent-not-working-with-nodejs/295638 "2022-01-27T22:49:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mayderson\_Santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayderson_santos/32/100932_2.png) [@Mayderson\_Santos](https://discuss.elastic.co/u/Mayderson_Santos)\
**Post date:** [January 27, 2022, 10:49pm UTC](https://discuss.elastic.co/t/apm-agent-not-working-with-nodejs/295638/1 "2022-01-27T22:49:53Z")

</div>

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](https://pastebin.com/5VUcgj2B)

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.

```auto
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-server](https://us1.discourse-cdn.com/elastic/original/3X/8/2/829cff86bfd197945b426a36c2bd1a72ac908592.png)

APM Agent not working

 ![apm-agent](https://us1.discourse-cdn.com/elastic/original/3X/a/2/a2207d6d30830357ae448e010b419dff5533338a.png)

APP NodeJS running

 ![2022-01-26-22:39:50](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b8408baf1575134e89c69c146a8982322348dde5.png)

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?

---

<div class="post-metadata">

**Author:** ![trentm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trentm/32/77647_2.png) [@trentm](https://discuss.elastic.co/u/trentm)\
**Post date:** [January 28, 2022, 5:35pm UTC](https://discuss.elastic.co/t/apm-agent-not-working-with-nodejs/295638/2 "2022-01-28T17:35:21Z")

</div>

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](https://nodejs.org/api/esm.html)). 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 `import`s lower down (e.g., `import http from 'http'`) will load those modules **before the `apm.start(...)` is executed.** [This APM agent document](https://www.elastic.co/guide/en/apm/agent/nodejs/current/es-modules.html) 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(...)`](https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-start-transaction), 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](https://github.com/elastic/apm-agent-nodejs/issues/1967)

---

<div class="post-metadata">

**Author:** ![Mayderson\_Santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayderson_santos/32/100932_2.png) [@Mayderson\_Santos](https://discuss.elastic.co/u/Mayderson_Santos)\
**Post date:** [January 29, 2022, 2:51am UTC](https://discuss.elastic.co/t/apm-agent-not-working-with-nodejs/295638/3 "2022-01-29T02:51:55Z")

</div>

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"**.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 18, 2022, 10:52pm UTC](https://discuss.elastic.co/t/apm-agent-not-working-with-nodejs/295638/4 "2022-02-18T22:52:00Z")

</div>

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