I am trying to configure an APM agent in my nodejs application code. I have installed the APM agent using the following command:
npm install elastic-apm-node --save
I then updated my application code using the following template:
// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
// Override the service name from package.json
// Allowed characters: a-z, A-Z, 0-9, -, _, and space
serviceName: 'my-service-name',
// Use if APM Server requires a secret token
secretToken: '',
// Set the custom APM Server URL (default: http://localhost:8200)
serverUrl: 'http://localhost:8200',
// Set the service environment
environment: 'my-environment'
})
But when I start up my application, the following is logged to the console:
{"log.level":"error","@timestamp":"2023-02-22T23:47:33.876Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error: error fetching APM Server version: connect ECONNREFUSED ::1:8200"}
{"log.level":"error","@timestamp":"2023-02-22T23:47:33.877Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error (ECONNREFUSED): connect ECONNREFUSED ::1:8200"}
{"log.level":"error","@timestamp":"2023-02-22T23:47:33.977Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error (ECONNREFUSED): connect ECONNREFUSED ::1:8200"}
{"log.level":"error","@timestamp":"2023-02-22T23:48:03.885Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"APM Server transport error (ECONNREFUSED): connect ECONNREFUSED ::1:8200"}
I'm not sure why I'm receiving these error messages or what to do about them.
That error message is the APM agent saying that it cannot find an APM server running at "http://localhost:8200" to which to send tracing data. That "http://localhost:8200" default only works if there actually is a locally running APM server.
Do you have an Elastic Cloud deployment? If so, if you visit the APM section (click "Services" in the sidebar), then you should get a screen like this:
That "Add data" button will take you to a tutorial page that walks through setup steps. Part of that setup will be a "Configure the agent" section that will show the serverUrl and secretToken for your deployment. For example:
It looks like curl reached the apm server and it is connected which is good
When you show secret_token you need to replace with your secret token I guess that API did not need that but when you connect from your node app you will need that BUT it looks like yours does not require one according to your image above... which is interesting not sure I have seen that before.
When you set up your server did you get a secret_token if so you need to use it in the node app.
Also can you try using 127.0.0.1 in your node app instead of localhost
Cool and Interesting that localhost was not resolved correctly ... put that in your "List"
You do not need a secret_token then, IF / When you want to move out of POC mode to production mode you should secure the APM with HTTPS and a secret_token
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.