elastic / elastic/apm-agent-nodejs
Can't get stack trace of errors passed through boom
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
**Describe the bug**
Elastic APM can't extract the stack trace of Errors processed by the [Boom](https://www.npmjs.com/package/@hapi/boom) module.
The Boom module is a pretty popular Node.js module for working with Errors in Node.js. It comes from and is used by the Hapi web framework, but is also used standalone.
**To Reproduce**
This agent uses the [v8 stack trace API](https://v8.dev/docs/stack-trace-api) to extract the stack trace from an Error object.
In this simplified example, we see how Boom is used on an error object to generate a boomified version of the error, and how that version, while technically still an instance of `Error`, doesn't trigger a call to `prepareStackTrace` once its `stack` property is accessed.
```js
const Boom = require('boom')
Error.prepareStackTrace = function (err, callsites) {
err.callsites = callsites
// ... code to generate and return stack trace as a string ...
}
const err = new Error('foo')
const boomifiedErr = new Boom(err)
console.log(boomifiedErr instanceof Error) // => true
err.stack // trigger v8 to generate the stack trace
boomifiedErr.stack // doesn't trigger the same effect on the boomified error
console.log(err.callsites) // => [...]
console.log(boomifiedErr.callsites) // => undefined
```
Contributor guide
Assessment
This issue has not been assessed yet.