elastic / elastic/apm-agent-nodejs

APM server response timeout when using await in async function

Open
#2,533 2 comments 0 reactions 1 assignee Claimed by @trentm View on GitHub
agent-nodejs community
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

I have a test.js file with the following code:

```
const apm = require('elastic-apm-node').start({
serviceName: 'testWatcher',
serverUrl: "http://********:8200/",
serverTimeout: "3s",
logUncaughtExceptions: true
});

const sleep = function (sec) {
return new Promise((resolve) => setTimeout(resolve, sec * 1000));
};

(async () => {
let currentTransaction = apm.startTransaction("Trans1", "trans");
currentTransaction.end("success");

await sleep(10);
})();
```

When I run it with:
`node test.js `

I always get the following output:
`{"log.level":"error","@timestamp":"2022-01-17T20:44:28.106Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error: APM Server response timeout (3000ms)"} `

If I remove the line with "await sleep(10)" or make "serverTimeout" option more than 10s (so that it is bigger than the "sleep" argument) then I don't have any errors and the transaction is logged to the server.

The response timeout also happens if I remove the lines:
```
// let currentTransaction = apm.startTransaction("Trans1", "trans");
// currentTransaction.end("success");
```

I have nodejs v.16.13.1, elastic-apm-node package ver. 3.27.0, running on Windows 10 Enterprise.

What I am doing wrong?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.