Closed
Description
Currently the JavaScript stack parsing is made up of:
- Highly modified version of Tracekit for the browser
- Mildly modified version of
node-stack-parse
for node.js
These are currently working well but there is scope for improvement:
- Multiple refactors have resulted in unused fields/code paths and unnecessary abstractions
- Downstream SDKs cannot configure the parser
- In Electron we need to use both Chrome and node.js line parsers in the renderer (Missing stacktrace in renderer process when using Node.js API integration sentry-electron#308)
- SDK users might want to exclude certain parsers to reduce bundle size
This quick PoC shows that the stack line parsers can be moved into individual functions that will allow features to be configurable.
Rough Plan
Make incremental improvements, starting with non-breaking changes:
- Refactor and improve tests and make some minor parser simplifications
- Remove unnecessary types and more simplifications
- Split line parsers into individual functions
- Migrate
node-stack-parse
to the common parser- Improve Node tests
- Move context line fetching to an integration
- Update docs to deprecate
frameContextLines
- Run node CI tests on Windows
- Refactor node parser to be line orientated and use common parser
- More stack parse improvements and consolidation
Then breaking changes for next major version:
- Add
stackParser
toinit
options so it can be overridden in downstream SDKs- This will require modifications to exports in eventbuilder
- ref: Expose configurable stack parser #4902
- Remove usages of deprecated
event.stacktrace
- Drop default Opera support since its not in the list of supported browsers
- Remove
frameContextLines
fromNodeOptions
since this will now be passed to the integration - Remove
eventbuilder
exports which were at some point used in@sentry/electron
A stack parser that can handle both Chrome and Node.js frames might be constructed like:
import { createStackParser } from '@sentry/utils';
import { chrome } from '@sentry/browser';
import { node} from '@sentry/node';
import { Exception } from '@sentry.types';
const stackParser = createStackParser(chrome, node);
try {
throw new Error('bad things');
} catch(e) {
const ex: Exception = stackParser(e);
}