stackTraceLimit: 0 removes the stacktraces outside of elastic APM
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: 0should 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 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.stackTraceLimitjust before anytime the agent callsError.captureStackTrace(...)and then restore the current value. A limitation with this is that this would only impact the stack trace capturing done for spans (whencaptureSpanStackTracesis true). The agent's serializes a stack traces for a captured error, however theError.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 setError.stackTraceLimitthemselves to something greater than or equal to the agent'sstackTraceLimitsetting.
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.