Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secretToken and serverUrl don't work at all! #3598

Closed
1 of 3 tasks
khteh opened this issue Aug 31, 2023 · 6 comments
Closed
1 of 3 tasks

secretToken and serverUrl don't work at all! #3598

khteh opened this issue Aug 31, 2023 · 6 comments
Assignees
Labels
agent-nodejs Make available for APM Agents project planning. community

Comments

@khteh
Copy link

khteh commented Aug 31, 2023

Describe the bug
Having these options in the configuration of your library does NOT work at all! We still have to define the env ELASTIC_APM_SECRET_TOKEN and ELASTIC_APM_SERVER_URL in our pod spec!

To Reproduce

Steps to reproduce the behavior:

  1. Use this config '...'
  2. Then call '....'
  3. Then do '....'
  4. See error

Expected behavior

Environment (please complete the following information)

  • OS: [e.g. Linux] Ubuntu 23.04
  • Node.js version: v20.3.1
  • APM Server version: 8.9.1
  • Agent version: 3.45.0

How are you starting the agent? (please tick one of the boxes)

  • 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

Additional context

Agent config options:

Click to expand
var apm = require('elastic-apm-node').start({
  // Override service name from package.json
  // Allowed characters: a-z, A-Z, 0-9, -, _, and space
  serviceName: 'my-apm',
  secretToken: process.env.ELASTIC_APM_SECRET_TOKEN,
  // Set custom APM Server URL (default: http://127.0.0.1:8200)
  serverUrl: 'https://my-apm-http:8200',
  // Only activate the agent if it's running in production
  active: process.env.NODE_ENV === 'production',
  // verifyServerCert: false,
  serverCaCertFile: '/etc/ca-certificates/tls.crt',

package.json dependencies:

Click to expand
replace this line with your dependencies section from package.json
@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Aug 31, 2023
@david-luna
Copy link
Member

Hi @khteh

in order to narrow the issue it would be very helpful to have some info regarding the env. At least the NodeJS and Agent versions. Also from version 3.47.0 the Agent logs info about the configuration and where it comes from so, for example if you run

ELASTIC_APM_SECRET_TOKEN=my-super-secret-token ELASTIC_APM_SERVER_URL=https://my-apm-server:8080 node ./examples/trace-http.js

You will see a log similar to this one

{
  "log.level": "info",
  "@timestamp": "2023-08-31T09:31:45.252Z",
  "log": {
    "logger": "elastic-apm-node"
  },
  "agentVersion": "3.49.1",
  "env": {
    "pid": 79616,
    "proctitle": "node",
    "os": "darwin 22.6.0",
    "arch": "arm64",
    "host": "moon.local.home",
    "timezone": "UTC+0200",
    "runtime": "Node.js v18.16.0"
  },
  "config": {
    "serviceName": {
      "source": "start",
      "value": "example-trace-http",
      "commonName": "service_name"
    },
    "serviceVersion": {
      "source": "default",
      "value": "3.49.1",
      "commonName": "service_version"
    },
    "serverUrl": {
      "source": "environment",
      "value": "https://my-apm-server:8080/",
      "commonName": "server_url"
    },
    "logLevel": {
      "source": "default",
      "value": "info",
      "commonName": "log_level"
    },
    "useElasticTraceparentHeader": {
      "source": "start",
      "value": false
    },
    "usePathAsTransactionName": {
      "source": "start",
      "value": true
    },
    "secretToken": {
      "source": "environment",  <-- value comes from an env var
      "value": "[REDACTED]",
      "commonName": "secret_token"
    }
  },
  "activationMethod": "require",
  "ecs": {
    "version": "1.6.0"
  },
  "message": "Elastic APM Node.js Agent v3.49.1"
}

But if you do not set the ENV vars and start the agent at the top of your file

require('elastic-apm-node').start({
  serviceName: 'example-trace-http',
  serverUrl: 'https://from-start-options-server:8000',
  secretToken: 'secret-token-from-options',
});

the output shows the source of the config is start

// Start options
{
  "log.level": "info",
  "@timestamp": "2023-08-31T09:34:12.496Z",
  "log": {
    "logger": "elastic-apm-node"
  },
  "agentVersion": "3.49.1",
  "env": {
    "pid": 80481,
    "proctitle": "node",
    "os": "darwin 22.6.0",
    "arch": "arm64",
    "host": "moon.local.home",
    "timezone": "UTC+0200",
    "runtime": "Node.js v18.16.0"
  },
  "config": {
    "serviceName": {
      "source": "start",
      "value": "example-trace-http",
      "commonName": "service_name"
    },
    "serviceVersion": {
      "source": "default",
      "value": "3.49.1",
      "commonName": "service_version"
    },
    "serverUrl": {
      "source": "start",
      "value": "https://from-start-options-server:8000/",
      "commonName": "server_url"
    },
    "logLevel": {
      "source": "default",
      "value": "info",
      "commonName": "log_level"
    },
    "useElasticTraceparentHeader": {
      "source": "start",
      "value": false
    },
    "usePathAsTransactionName": {
      "source": "start",
      "value": true
    },
    "secretToken": {
      "source": "start",   <-- value comes from the start options
      "value": "[REDACTED]",
      "commonName": "secret_token"
    }
  },
  "activationMethod": "require",
  "ecs": {
    "version": "1.6.0"
  },
  "message": "Elastic APM Node.js Agent v3.49.1"
}

Having this info (nodejs & agent versions, 1st log line) would be a very good input to start looking into a way of reproducing the issue.

@david-luna
Copy link
Member

@khteh

could I close this one based on your response in #3568 ?

are you still having issues configuring the nodejs agent?

@khteh
Copy link
Author

khteh commented Aug 31, 2023

No!

@khteh
Copy link
Author

khteh commented Aug 31, 2023

This duplicate config needs fix!

@david-luna
Copy link
Member

Okay

could you share the log line I mentioned in my previous comment? (guessing you have agent 3.47.0 or higher)

@khteh
Copy link
Author

khteh commented Sep 1, 2023

I don't see the issue after upgraded to the latest version. Removed redundant ELASTIC_APM_SERVER_URL env.

@khteh khteh closed this as completed Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. community
Projects
None yet
Development

No branches or pull requests

2 participants