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

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

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

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

This both code snnipet i am using it

Hi @Maheta_Hemendra_Bhav and welcome :slight_smile:

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

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

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


i am using

         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

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.

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.