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

Node: StackFrame.module incorrectly parsed from filename #10000

Closed
timfish opened this issue Dec 31, 2023 · 0 comments · Fixed by #10001
Closed

Node: StackFrame.module incorrectly parsed from filename #10000

timfish opened this issue Dec 31, 2023 · 0 comments · Fixed by #10001
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug

Comments

@timfish
Copy link
Collaborator

timfish commented Dec 31, 2023

The stack frame module property should be a:

Platform-specific module path (e.g. sentry.interfaces.Stacktrace).

Take this example...

If require.main.filename (the app entry point) is /Users/Tim/app/main.js and the filename we're trying to resolve module name for is /Users/Tim/app/some/great/feature.js, I would expect the module to end up being something like some.great.feature, however it ends up as just feature.

If we look at the code for getModuleFromFilename we can see that in the case of the above input, normalizedBase ends up being /Users/Tim/app/some/great/ whereas I think it should probably be /Users/Tim/app/.

let { root, dir, base: basename, ext } = posix.parse(normalizedFilename);
const base = (require && require.main && require.main.filename && dir) || global.process.cwd();
const normalizedBase = `${base}/`;

It looks like this was broken here in #7415, which means it's been broken since around v7.45.0.

Before, base was calculated from the dirname(require.main.filename) rather than the dir of the filename we're trying to resolve:

  const base = normalizePath(
    `${(require && require.main && require.main.filename && dirname(require.main.filename)) || global.process.cwd()}/`,
  );

This likely happened because the tests for this have were not (and still aren't) sufficient:
https://github.com/getsentry/sentry-javascript/blob/develop/packages/node/test/module.test.ts

@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant