# APM Server transport error (ECONNRESET): socket hang up

**URL:** <https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [December 13, 2022, 9:22pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165 "2022-12-13T21:22:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kvaga](https://avatars.discourse-cdn.com/v4/letter/k/ee7513/32.png) [@kvaga](https://discuss.elastic.co/u/kvaga)\
**Post date:** [December 13, 2022, 9:22pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/1 "2022-12-13T21:22:31Z")

</div>

we are developing node.js app (in k8s), logs stored in ELK Stack 8.3.3  
in attempt to configure APM with Node.js Agent ([elastic-apm-node - npm](https://www.npmjs.com/package/elastic-apm-node))

get error

APM Server transport error (ECONNRESET): socket hang up

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/0/d096f792dbba33bbcdb5ec93501f885488e73f63.jpeg)

---

<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:** [December 13, 2022, 10:27pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/2 "2022-12-13T22:27:34Z")

</div>

Hello @kvaga,

The "APM Server transport error (ECONNRESET): socket hang up" error message is the Node.js APM agent saying that APM server ended a connection while the APM agent was trying to talk to it. In earlier versions of the agent (before [this issue was resolved](https://github.com/elastic/apm-agent-nodejs/issues/2594)) this _could_ happen occasionally due to a race in TCP-keepalive handling.

What version of the APM agent are you using?

Do you get this "APM Server transport error" **everytime the APM agent starts**? Or is it an error that only happens occasionally?

Are you able to get some "trace"-level log output from the APM agent and show that here? You can turn on trace-level logging by adding `logLevel: 'trace'` to the `apm.start({...})` method, or by setting the `ELASTIC_APM_LOG_LEVEL=trace` environment variable.

---

<div class="post-metadata">

**Author:** ![kvaga](https://avatars.discourse-cdn.com/v4/letter/k/ee7513/32.png) [@kvaga](https://discuss.elastic.co/u/kvaga)\
**Post date:** [December 14, 2022, 7:31am UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/3 "2022-12-14T07:31:17Z")

</div>

error every few seconds

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/1/c15709fd73f20f3a63236abc9941dec4dab17f75.png)

error port in example fixed to 8200

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/e/9e5ea2fd23dfa5dd0781c4bc77ea3f63d325d995.jpeg)

i`ll try to turn on logLevel: 'trace'

---

<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:** [December 14, 2022, 6:57pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/4 "2022-12-14T18:57:16Z")

</div>

> [@kvaga](#):
>
> error every few seconds

That looks like it is every ~30s, which is about how often the APM agent will attempt to send metrics to the APM server. So it seems likely that every attempt the APM agent makes to talk to the configured `serverUrl` results in the APM server unexpectedly closing the connection.

The APM agent logs from `logLevel: 'trace'` will show a little bit more detail.

Your `serverUrl` uses `http:` rather than `https:`. Is that expected for your setup? Also you are using Basic auth (`pmap-logs:$password@`) in your `serverUrl`. Do you have a proxy in front of your APM server that is handling that authentication? My experience is with using a `secretToken` or `apiKey` with APM server for auth. See [Secure communication with APM agents | APM User Guide [8.11] | Elastic](https://www.elastic.co/guide/en/apm/guide/current/secure-agent-communication.html) and [Configuration options | APM Node.js Agent Reference [4.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#secret-token)

---

<div class="post-metadata">

**Author:** ![kvaga](https://avatars.discourse-cdn.com/v4/letter/k/ee7513/32.png) [@kvaga](https://discuss.elastic.co/u/kvaga)\
**Post date:** [December 15, 2022, 7:44am UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/5 "2022-12-15T07:44:14Z")

</div>

> [@trentm](#):
>
> rather

after correcting https to http, i see metrisc cpu & memory, but it`s not transactions, errors...

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/d/2d4a26b3d3e9cac789ef3884afe161d5efc10030.png)

logs from elastic-apm-node

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/9/99b2a83fe9ea2af6941b55d5977a5e4c345a0e89.png)

---

<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:** [December 15, 2022, 11:25pm UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/6 "2022-12-15T23:25:57Z")

</div>

Okay, good that data (metrics) is getting from the APM agent to APM server.

About getting other tracing data (transactions, spans, errors) report:

1. Automatic instrumentation of NestJS is not [currently supported](https://www.elastic.co/guide/en/apm/agent/nodejs/current/supported-technologies.html#compatibility-frameworks) by the Node.js APM agent. So it is possible that there is a limitation here. I'm am not familiar enough with NestJS to know if we should expect some raw HTTP instrumentation to work. There is an issue here that requests official NestJS instrumentation: [When will the nest.js plugin be supported. · Issue #1836 · elastic/apm-agent-nodejs · GitHub](https://github.com/elastic/apm-agent-nodejs/issues/1836)

2. The first thing to try adjusting is to try to make sure that the APM agent is started _before_ your other modules are imported. One thing to try is to change your `import apm ...` and `apm.start()` to:

```typescript
import 'elastic-apm-node/start'; // put this before any other imports
// ...

```

and then use environment variables or an "elastic-apm-node.js" config module to configure the APM agent. Another technique is to have a separate "initapm.ts" module as described at [Starting the agent | APM Node.js Agent Reference [3.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/current/starting-the-agent.html#start-option-separate-init-module)

(This doc section describes some surprises with TypeScript and getting the APM agent to start first: [Starting the agent | APM Node.js Agent Reference [3.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/current/starting-the-agent.html#start-gotchas))

---

<div class="post-metadata">

**Author:** ![kvaga](https://avatars.discourse-cdn.com/v4/letter/k/ee7513/32.png) [@kvaga](https://discuss.elastic.co/u/kvaga)\
**Post date:** [December 23, 2022, 6:35am UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/7 "2022-12-23T06:35:54Z")

</div>

OK a see

оn DEV - OK

we add same connection to APM ELK ( + add enviroment: production)  
i see, metrics for CPU/mem

![image](https://us1.discourse-cdn.com/elastic/original/3X/6/3/63ef481ba3cd58109d9027bf3a6ea4db9ddd5ca8.png)

but there is no transaction

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e3659133216d6f2641140402369d39de662be6c.png)  
apm module is working  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/f/2fb236e7d8c30cb38fb7bcbaaf5ddcd6a56f48db.png)

how to add data from apm about transaction ... etc

---

<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:** [January 13, 2023, 2:36am UTC](https://discuss.elastic.co/t/apm-server-transport-error-econnreset-socket-hang-up/321165/8 "2023-01-13T02:36:11Z")

</div>

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