APM agent an Typescript

Hello.

I'm trying to use APM in a Node+Express+Typescript backend. I followed this:

https://www.elastic.co/guide/en/apm/agent/nodejs/current/es-modules.html

So now I have this on my tsconfig.json:

"esModuleInterop": true,

And in my app.ts I try to start the agent like this:

import apm from 'elastic-apm-node/start';

const apmClient = apm.start({
    serviceName:
        process.env.ELASTIC_APM_SERVICE_NAME || 'elastic-apm-demo-middleware',
    serverUrl: process.env.ELASTIC_APM_SERVER_URL || 'http://apm-server:8200',
    secretToken: process.env.ELASTIC_APM_SECRET_TOKEN || '',
    logUncaughtExceptions: true
});

Problems:

  1. It generates an error, which is sent to the APM server: Do not call .start() more than once
  2. It points to the wrong line... I guess this is due the transpilation process, so I'll have to find how to publish the source maps...

What am I not getting right in the agent's start process?

Thank you

1 Like

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