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

stackTraceLimit: 0 removes the stacktraces outside of elastic APM

Open n-e opened this issue 4 years ago • 1 comments

To Reproduce

The following program :

const apmModule = require('elastic-apm-node');
apmModule.start({
  stackTraceLimit: 0,
  serverUrl: 'xxx',
  secretToken: 'yyy',
  active: true,
  centralConfig: false,
});

const main = () => {
  console.trace('abcd')
  console.log(new Error().stack)
}

main()

prints :

[object Object]
Error

(ie. it doesn't print the stack frames)

Expected behavior

  • stackTraceLimit: 0 should only disable the stack trace collection for elastic APM, but still show the stack frame in Error.stack or console.trace.
  • When doing console.trace(message), the message should be printed instead of [object Object]

Environment (please complete the following information)

  • OS: macOS 11.6.2
  • Node.js version:
  • APM Server version:
  • Agent version: 3.27.0

n-e avatar Feb 02 '22 12:02 n-e

@n-e Yah, stackTraceLimit is being set directly on the global Error.stackTraceLimit, so it definitely does affect behaviour outside the agent.

I agree this is potentially surprising. At the least we should clarify in the agent configuration docs the impact this has.

Some issues/visible changes if we were to change this config var to not modify Error.stackTraceLimit:

  • One option would be to temporarily set Error.stackTraceLimit just before anytime the agent calls Error.captureStackTrace(...) and then restore the current value. A limitation with this is that this would only impact the stack trace capturing done for spans (when captureSpanStackTraces is true). The agent's serializes a stack traces for a captured error, however the Error.captureStackTrace(...) has already been run by the time the agent sees the Error instance. This means that if a user wants a deep stack trace on collected errors, then they would need to set Error.stackTraceLimit themselves to something greater than or equal to the agent's stackTraceLimit setting.

Note to self: Ask the Java agent folks if https://www.elastic.co/guide/en/apm/agent/java/current/config-stacktrace.html#config-stack-trace-limit has similar implications in Java-land, or if its impact is limited to the agent's collected stacks.

trentm avatar Feb 02 '22 19:02 trentm