# I have integrated Elastic Apm in nextjs , problem is that apm is working in localhost but not working in Qa(while deploying)

**URL:** <https://discuss.elastic.co/t/i-have-integrated-elastic-apm-in-nextjs-problem-is-that-apm-is-working-in-localhost-but-not-working-in-qa-while-deploying/357203>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [April 11, 2024, 11:45am UTC](https://discuss.elastic.co/t/i-have-integrated-elastic-apm-in-nextjs-problem-is-that-apm-is-working-in-localhost-but-not-working-in-qa-while-deploying/357203 "2024-04-11T11:45:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maheta\_Hemendra\_Bhav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maheta_hemendra_bhav/32/123992_2.png) [@Maheta\_Hemendra\_Bhav](https://discuss.elastic.co/u/Maheta_Hemendra_Bhav)\
**Post date:** [April 11, 2024, 11:45am UTC](https://discuss.elastic.co/t/i-have-integrated-elastic-apm-in-nextjs-problem-is-that-apm-is-working-in-localhost-but-not-working-in-qa-while-deploying/357203/1 "2024-04-11T11:45:34Z")

</div>

Version: "@elastic/apm-rum": "^5.16.0",  
"elastic-apm-node": "^4.5.0",

```auto
if (!apm.isStarted()) {
     // Start the APM agent
     apm.start({
         serverUrl: 'http://abc.com',
         serviceName: 'next-js',
         environment: 'staging',
     });
 }

apm.setTransactionName('GET ' + context.resolvedUrl);

```

This both code snnipet i am using it

---

<div class="post-metadata">

**Author:** ![David\_Luna\_Bistuer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_luna_bistuer/32/122147_2.png) [@David\_Luna\_Bistuer](https://discuss.elastic.co/u/David_Luna_Bistuer)\
**Post date:** [April 11, 2024, 2:19pm UTC](https://discuss.elastic.co/t/i-have-integrated-elastic-apm-in-nextjs-problem-is-that-apm-is-working-in-localhost-but-not-working-in-qa-while-deploying/357203/2 "2024-04-11T14:19:49Z")

</div>

Hi @Maheta_Hemendra_Bhav and welcome 🙂

In order to have more context I would need you to answer a couple of questions.

**Could you give environment details?**

- OS: [e.g. Linux]
- Node.js version:
- APM Server version:
- Agent version:

**How are you starting the agent?**

- Calling `agent.start()` directly (e.g. `require('elastic-apm-node').start(...)`)
- Requiring `elastic-apm-node/start` from within the source code
- Starting node with `-r elastic-apm-node/start`

The code snippet you provided could be in the app code or in a separate file that could be required when starting the app like this  
`node -r apm-start.js my-app.js`

If the snippet is in your application code. Is it placed at the top of the main file before any required packages?

**Is there any bundler in place?**  
If your app gets bundled before deploying to QA the agent may have some issues with the bundled code. [reference](https://www.elastic.co/guide/en/apm/agent/nodejs/current/starting-the-agent.html#start-bundlers)

**Is the QA env behind a proxy ?**  
Sometimes a proxy can block the traffic from the service to the AMP server. Check if that node can ping to the APM server, a `curl` is enough

here its an example

```bash
curl -i http://apm-server-host
HTTP/2 200
date: Thu, 11 Apr 2024 14:28:22 GMT
x-cloud-request-id: n7qpERl4R6amVKa7zyaidg
x-content-type-options: nosniff
x-found-handling-cluster: cc9999de999999999d99df0bd63700cb
x-found-handling-instance: instance-0000000000
content-length: 0

```

---

<div class="post-metadata">

**Author:** ![Maheta\_Hemendra\_Bhav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maheta_hemendra_bhav/32/123992_2.png) [@Maheta\_Hemendra\_Bhav](https://discuss.elastic.co/u/Maheta_Hemendra_Bhav)\
**Post date:** [April 12, 2024, 6:33am UTC](https://discuss.elastic.co/t/i-have-integrated-elastic-apm-in-nextjs-problem-is-that-apm-is-working-in-localhost-but-not-working-in-qa-while-deploying/357203/3 "2024-04-12T06:33:00Z")

</div>

OS: MAC  
NODE VERSION: 18.19.1

i am using

```auto
apm.start({
         serverUrl: 'http://abc.com',
         serviceName: 'next-js',
         environment: 'staging',
     });

```

apm.start(...) directly

starting my app with this script  
cross-env APP\_ENV=dev env-cmd -f .env.development next dev

i am using nextjs and there is a file called next.config.js in that file webpack is there

HTTP/1.1 200 OK  
Content-Type: application/json  
X-Content-Type-Options: nosniff  
Date: Fri, 12 Apr 2024 06:29:55 GMT  
Content-Length: 150  
Via: 1.1 google  
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

{  
"build\_date": "2023-11-07T18:53:29Z",  
"build\_sha": "f0deedvbnm,4830530d39e136f3e88ee45asdfghjklb20cfacc241",  
"publish\_ready": true,  
"version": "8.11.1"  
}

i am using nextjs and writing this line apm.setTransactionName('GET ' + context.resolvedUrl);  
inside getServerSideProps, using server side rendering

---

<div class="post-metadata">

**Author:** ![David\_Luna\_Bistuer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_luna_bistuer/32/122147_2.png) [@David\_Luna\_Bistuer](https://discuss.elastic.co/u/David_Luna_Bistuer)\
**Post date:** [April 16, 2024, 8:13am UTC](https://discuss.elastic.co/t/i-have-integrated-elastic-apm-in-nextjs-problem-is-that-apm-is-working-in-localhost-but-not-working-in-qa-while-deploying/357203/4 "2024-04-16T08:13:28Z")

</div>

Hi @Maheta_Hemendra_Bhav

I didn't notice you are developing an `nextjs` application. This framework needs a specific set of steps to be instrumented by Elastic's APM agent which are described in this page [Get started with Next.js | APM Node.js Agent Reference [4.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/current/nextjs.html).

If you cannot use npm scripts to start the app in QA make sure you add `NODE_OPTIONS="--require=elastic-apm-node/start-next.js"` environment var in your script.

Cheers,  
David
