apm-agent-nodejs icon indicating copy to clipboard operation
apm-agent-nodejs copied to clipboard

Export the default config value

Open root-io opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. Is it possible to get the default value of the sanitizeFieldNames config ? I need to append a new value to the default array without having to copy the default value from the doc.

import agent from "elastic-apm-node";

const apm = agent.start({
  sanitizeFieldNames: [
    "password",
    "passwd",
    "pwd",
    "secret",
    "*key",
    "*token*",
    "*session*",
    "*credit*",
    "*card*",
    "*auth*",
    "set-cookie",
    "pw",
    "pass",
    "connect.sid",
    "MY_NEW_VALUE",
  ],
});

Describe the solution you'd like

const agent, { getDefaultConfig } from "elastic-apm-node";

const apm = agent.start({
  sanitizeFieldNames: [
    ...getDefaultConfig.sanitizeFieldNames
    "MY_NEW_VALUE",
  ],
});

Related to https://github.com/elastic/apm-agent-dotnet/issues/1294

root-io avatar Mar 19 '22 16:03 root-io

Thanks for opening the feature request @root-io.

You're right that while you can grab default values by doing something like

// private-ish API
const agent = require('elastic-apm-node')
console.log(agent._conf.sanitizeFieldNames)

or

// private-ish API
console.log(require('elastic-apm-node/lib/config').DEFAULTS.sanitizeFieldNames)

that we don't have a formal, semver versioned API for grabbing the default configuration values for a particular field. The above might change in the future.

Feature request logged and I'll bring it up at our next team meeting (since, as noted in https://github.com/elastic/apm-agent-dotnet/issues/1294, changes here might skirt into multi-language agent spec territory)

astorm avatar Mar 21 '22 20:03 astorm

Thanks! I'll use your suggestion until then ;)

root-io avatar Mar 21 '22 20:03 root-io

What about us exporting CONFIG_DEFAULTS on require('elastic-apm-node')? So the usage could then be:

const apm = require('elastic-apm-node')
apm.start({
  sanitizeFieldNames: [...apm.CONFIG_DEFAULTS.sanitizeFieldNames, 'MY_NEW_VALUE'],
  // ...
})

trentm avatar Mar 24 '22 16:03 trentm