Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Stack Parsing #4543

Closed
14 of 15 tasks
timfish opened this issue Feb 10, 2022 · 8 comments
Closed
14 of 15 tasks

Refactor Stack Parsing #4543

timfish opened this issue Feb 10, 2022 · 8 comments

Comments

@timfish
Copy link
Collaborator

timfish commented Feb 10, 2022

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:

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:

Then breaking changes for next major version:

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);
}
@timfish
Copy link
Collaborator Author

timfish commented Feb 14, 2022

At some point this week I'm guessing #3729 is going to become a blocker to progress.

I've run the tests locally both on macOS and Windows and everything passes so I'm at a bit of a loss as to how to fix this!

@timfish
Copy link
Collaborator Author

timfish commented Feb 14, 2022

When we finally allow users to pass in/configure stack line parsers we run into the issue of order/priority. The order that the line parsers are attempted is key so we need to add some kind of priority.

Currently the line parser type is:

type StackLineParser = (line: string) => StackFrame | undefined;

We could add a property to the function and change the type to something like:

interface StackLineParser {
  (line: string): StackFrame | undefined;
  priority: number;
}

You could configure this like:

const myParser: StackLineParser = Object.assign(
  line => {
    // parser here
  }, 
  { priority: 10 }
);

But that would add quite a bit to the bundle.

A helper function might make parser creation take up less bundle size:

function createParser(fn:  (line: string): StackFrame | undefined, priority: number): StackLineParser {
  return Object.assign(fn, { priority });
}

const myParser = createParser( line => { /* parser here */ }, 10);

Alternatively, a plain object interface is an option:

interface StackLineParser {
  fn: (line: string): StackFrame | undefined;
  p: number;
}

@AbhiPrasad
Copy link
Member

Alternatively, a plain object interface is an option:

Could we maybe use an array? I used a similar strategy for the envelope types: https://github.com/getsentry/sentry-javascript/pull/4527/files#diff-98566cdbe00d44614c2fa27bf3e2ffabc236cf66528242495ea172d7fcb6ca0aR18-R25

@timfish
Copy link
Collaborator Author

timfish commented Feb 14, 2022

That would work.

Those array type definitions are 👌

@timfish
Copy link
Collaborator Author

timfish commented Mar 2, 2022

Trying to decide how to expose the stack parser config to Browser SDK consumers and the Electron SDK.

I can put it in the init options for the browser SDK, and then it'll need to be passed down to every function in eventbuilder. It's a bit messy but can't really think of a better way.

Do you see any point exposing the parser for other SDKs?

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Mar 2, 2022

Do you see any point exposing the parser for other SDKs?

React Native is the only one that comes to my mind here, but they seem to just use browser's stuff https://github.com/getsentry/sentry-react-native/blob/33232d9ef157e4c4059f618cee348f9bd16af8fd/src/js/backend.ts#L45-L61

@AbhiPrasad
Copy link
Member

@timfish this should be good to close right?

@timfish
Copy link
Collaborator Author

timfish commented Apr 26, 2022

Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants