# Zlib: invalid header error in node js apm agent

**URL:** <https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [May 25, 2022, 1:44pm UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616 "2022-05-25T13:44:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkatkumar229](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatkumar229/32/104663_2.png) [@venkatkumar229](https://discuss.elastic.co/u/venkatkumar229)\
**Post date:** [May 25, 2022, 1:44pm UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616/1 "2022-05-25T13:44:37Z")

</div>

**Kibana version** : 7.17.3

**Elasticsearch version** : 7.17.3

**APM Server version** : 7.17.3

**APM Agent language and version** : node.js and version 3

**Browser version** : Chrome

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**:npm install

**Fresh install or upgraded from other version?** : Fresh install

**Is there anything special in your setup?** Directly sending the logs to Elasticsearch cloud apm and nothing in between.

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**: {"log.level":"error","@timestamp":"2022-05-25T12:33:20.932Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error (400): Unexpected APM Server response\nAPM Server accepted 0 events in the last request\nError: zlib: invalid header"}

**Steps to reproduce** :  
1.  
2.  
3.

**Errors in browser console (if relevant)**: {"log.level":"error","@timestamp":"2022-05-25T12:33:20.932Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error (400): Unexpected APM Server response\nAPM Server accepted 0 events in the last request\nError: zlib: invalid header"}

**Provide logs and/or server output (if relevant)**:

---

<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:** [May 25, 2022, 3:46pm UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616/2 "2022-05-25T15:46:20Z")

</div>

Hi @venkatkumar229. It sounds like you are attempting to use our [Node.js APM agent](https://github.com/elastic/apm-agent-nodejs) -- intended for server-side Node.js apps -- in a JS app that runs in the browser. If I understood correctly, you will want to use our [APM Real User Monitoring (RUM) JavaScript agent](https://github.com/elastic/apm-agent-rum-js).

Please let me know if I have misunderstood you.

---

<div class="post-metadata">

**Author:** ![venkatkumar229](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatkumar229/32/104663_2.png) [@venkatkumar229](https://discuss.elastic.co/u/venkatkumar229)\
**Post date:** [May 26, 2022, 7:18am UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616/3 "2022-05-26T07:18:34Z")

</div>

Hi @trentm ,

We are trying to install APM on the server side to get the application metrics. When we try to run apm from local we are able to see the apm service in kibana but when we commit the code to a server and run the application we are not able to see the service and getting the "zlib" invalid header error.

When we are trying from the server we are using a internet gateway inbetween node.js application and Elasticsearch.

Not sure why we are getting the error when we try to run the apm in server side. Could you please help us.

---

<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:** [May 26, 2022, 8:37pm UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616/4 "2022-05-26T20:37:10Z")

</div>

@venkatkumar229 When the Node.js APM Agent sends data to the APM Server it uses an HTTP request with _gzip compression_ (and set the `content-encoding: gzip` header). The "zlib: invalid header" message tells me that APM Server is receiving a request that says the request body is gzipped (i.e. the request headers have `content-encoding: gzip`), but either the request body is corrupted, or it is no longer compressed gzip data.

> we are using a internet gateway inbetween node.js application and Elasticsearch.

Is this some software that you run that is between your Node.js application (where the APM Agent is running) and _the APM Server_ it is configured to talk to (via `serverUrl` or via the `ELASTIC_APM_SERVER_URL` environment variable)? If so, is it possible that this gateway does not support gzip'd requests?

---

<div class="post-metadata">

**Author:** ![venkatkumar229](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatkumar229/32/104663_2.png) [@venkatkumar229](https://discuss.elastic.co/u/venkatkumar229)\
**Post date:** [May 27, 2022, 6:40am UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616/5 "2022-05-27T06:40:57Z")

</div>

Hi @trentm ,

We have set the compression to false in the node.js agent to solve the issue but no luck.

`spanCompressionEnabled: false

---

<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:** [May 31, 2022, 9:05pm UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616/6 "2022-05-31T21:05:48Z")

</div>

@venkatkumar229 Sorry, I didn't see your reply until now.

`spanCompressionEnabled` is about the APM agent taking a number of consecutive spans that are similar and merging them into a single composite span that represents them all ([Span compression | APM User Guide [8.2] | Elastic](https://www.elastic.co/guide/en/apm/guide/8.2/span-compression.html)). It is unrelated to the gzip compression that the APM agent uses for its HTTP requests to APM server.

Are you able to give any details about the internet gateway that you are using?

---

<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:** [June 21, 2022, 5:06pm UTC](https://discuss.elastic.co/t/zlib-invalid-header-error-in-node-js-apm-agent/305616/7 "2022-06-21T17:06:00Z")

</div>

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