# Using APM NodeJS in a NestJS enviroment - Can't initialize agent

**URL:** <https://discuss.elastic.co/t/using-apm-nodejs-in-a-nestjs-enviroment-cant-initialize-agent/318699>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [November 10, 2022, 10:29pm UTC](https://discuss.elastic.co/t/using-apm-nodejs-in-a-nestjs-enviroment-cant-initialize-agent/318699 "2022-11-10T22:29:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_k/32/113243_2.png) [@Daniel\_K](https://discuss.elastic.co/u/Daniel_K)\
**Post date:** [November 10, 2022, 10:29pm UTC](https://discuss.elastic.co/t/using-apm-nodejs-in-a-nestjs-enviroment-cant-initialize-agent/318699/1 "2022-11-10T22:29:18Z")

</div>

I'm trying to autenticate ELK using the NodeJS agent in a NestJS environment. I followed the Express tutorial to use the NodeJS agent.

On the application bootstrap, I'm getting this errors:

```auto
{"log.level":"error","@timestamp":"2022-11-10T22:15:10.552Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error (400): Unexpected APM Server response\n{\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason\":\"failed to parse\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"failed to parse\",\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"Malformed content, found extra data after parsing: START_OBJECT\"}},\"status\":400}"}

{"log.level":"trace","@timestamp":"2022-11-10T22:15:10.552Z","log":{"logger":"elastic-apm-node"},"event.module":"apmclient","reqId":"3be13b70d60c929068f15d8cc99729aa","concluded":false,"ecs":{"version":"1.6.0"},"error":{"type":"Error","message":"Unexpected APM Server response","stack_trace":"Error: Unexpected APM Server response\n at processIntakeErrorResponse (/PROJECT_DIR/node_modules/elastic-apm-http-client/index.js:1489:15)\n at IncomingMessage.<anonymous> (/PROJECT_DIR/node_modules/elastic-apm-http-client/index.js:1044:17)\n at IncomingMessage.emit (events.js:412:35)\n at endReadableNT (internal/streams/readable.js:1334:12)\n at processTicksAndRejections (internal/process/task_queues.js:82:21)"},"message":"completePart intakeRes"}

```

My stack versions:  
"@nestjs/common": "^7.6.18",  
"@nestjs/core": "^7.6.18",  
"@nestjs/jwt": "^7.2.0",  
"@nestjs/mongoose": "^7.2.4",  
"@nestjs/passport": "^7.1.6",  
"@nestjs/platform-express": "^7.6.18"  
(...)  
"elastic-apm-node": "^3.40.0",

Elastic/Kibana version: v7.16.2

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [November 11, 2022, 9:19am UTC](https://discuss.elastic.co/t/using-apm-nodejs-in-a-nestjs-enviroment-cant-initialize-agent/318699/2 "2022-11-11T09:19:40Z")

</div>

@Daniel_K welcome to the forum!

The first error message includes a response that is coming from Elasticsearch. Have you configured the Node.js agent to connect to Elasticsearch? You need to connect it to Elastic APM Server.

---

<div class="post-metadata">

**Author:** ![Daniel\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_k/32/113243_2.png) [@Daniel\_K](https://discuss.elastic.co/u/Daniel_K)\
**Post date:** [November 11, 2022, 4:46pm UTC](https://discuss.elastic.co/t/using-apm-nodejs-in-a-nestjs-enviroment-cant-initialize-agent/318699/3 "2022-11-11T16:46:08Z")

</div>

I'm starting using ELK, and I didn't know APM was a separate service running in a different port.

After this, I got a error in TLS communication, but I found answers searching at google.

Communication agent =\> APM service is working now. Thanks for the help!

---

<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:** [December 2, 2022, 12:46pm UTC](https://discuss.elastic.co/t/using-apm-nodejs-in-a-nestjs-enviroment-cant-initialize-agent/318699/4 "2022-12-02T12:46:25Z")

</div>

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