-
Notifications
You must be signed in to change notification settings - Fork 51
fix(plugin-manager): Respect sourcemap.ignore values for injecting debugIDs
#836
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
Conversation
| export function serializeIgnoreOptions(ignoreValue: string | string[] | undefined): string[] { | ||
| const DEFAULT_IGNORE = ["node_modules"]; | ||
|
|
||
| const ignoreOptions: string[] = Array.isArray(ignoreValue) | ||
| ? ignoreValue | ||
| : typeof ignoreValue === "string" | ||
| ? [ignoreValue] | ||
| : DEFAULT_IGNORE; | ||
|
|
||
| return ignoreOptions.reduce( | ||
| (acc, value) => acc.concat(["--ignore", String(value)]), | ||
| [] as string[] | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a simplified version of: https://github.com/getsentry/sentry-cli/blob/9f34df859bf2975155aad0fe5c6c423b45c07084/lib/helper.ts#L199-L217
Lms24
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me. One comment to confirm, otherwise ready to go :)
| * Temporary workaround until we expose a function for injecting debug IDs. Currently, we directly call `execute` with CLI args to inject them. | ||
| */ | ||
| export function serializeIgnoreOptions(ignoreValue: string | string[] | undefined): string[] { | ||
| const DEFAULT_IGNORE = ["node_modules"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I wonder if including node_modules has any implications but I don't think so: We inject debug ids into emitted bundles, meaning the node_modules required by the bundle should already be in there.
Also, the ignore option for upload also defaults to node_modules, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not ignoring it can result in file import loops (this is what happens in e.g. Nuxt).
And yes, it's also the default option for uploading source maps.
| ? ignoreValue | ||
| : typeof ignoreValue === "string" | ||
| ? [ignoreValue] | ||
| : DEFAULT_IGNORE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if we don't always want to add this ignore? In the sense that a user should likely never inject debug ids in node_modules but they usually want to additionally ignore other paths etc. no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! I just resembled the existing logic from the CLI here (user-provided value overwrites): https://github.com/getsentry/sentry-cli/blob/a618fb33ddfc3646ac8d5e2391ea1ee6e208b709/lib/releases/index.ts#L159-L161
Either we document, that ignore has a default value of 'node_modules', which gets overwritten or we just always add 'node_modules'. I am leaning towards just better documenting this default value, so it's still possible to overwrite it.
@Lms24 any opinions on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So according to this doc, the default is [], which seems like its wrong either way (?).
I am leaning towards just better documenting this default value, so it's still possible to overwrite it.
Me too, because the alternative would be a behaviour break, right? So let's avoid that 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default is [], which seems like its wrong either way
In the JS bundler plugins, this is correct. But this value is passed down a bunch of times:
| CLI | Bundler Plugins | Meta-Framework SDK |
|---|---|---|
adds 'node_modules' as default |
uses CLI in plugin manager (no defaults) | uses bundler plugins (no defaults) |
Maybe it's worth applying this default in the bundler plugins already, as we could align the behavior better on this stage.
Only the Plugin Manger uses the CLI under the hood, and there are no defaults otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked offline, created an issue: #838
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛Plugin Manager
Documentation 📚
Build / dependencies / internal 🔧
🤖 This preview updates automatically when you update the PR. |
| [ | ||
| "sourcemaps", | ||
| "inject", | ||
| ...serializeIgnoreOptions(options.sourcemaps?.ignore), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The injectDebugIds function defaults to ignoring node_modules, but uploadSourcemaps does not, causing source maps to be uploaded without debug IDs.
Severity: HIGH
Suggested Fix
Ensure the uploadSourcemaps function applies the same default ignore behavior as injectDebugIds. When options.sourcemaps?.ignore is undefined, it should default to ignoring ["node_modules"]. This will align the set of files that have debug IDs injected with the set of files that are uploaded as source maps.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/bundler-plugin-core/src/build-plugin-manager.ts#L561
Potential issue: There is an inconsistency in how default ignore behavior is handled
between `injectDebugIds` and `uploadSourcemaps`. When `options.sourcemaps?.ignore` is
undefined, `injectDebugIds` defaults to ignoring `node_modules`. However,
`uploadSourcemaps` does not apply this default in either its direct upload or prepare
modes. This causes source maps from `node_modules` to be uploaded without the
corresponding debug IDs being injected. As a result, the association between the source
code and the error in Sentry is broken for these files, rendering the uploaded source
maps unusable and wasting upload bandwidth.
Did we get this right? 👍 / 👎 to inform future reviews.
In this PR, Nuxt will use the build plugin manager to upload source maps at the end of the build. Currently, it fails because the
ignoreoption is not respected.injectDebugIdsis currently using the "raw"executefunction and doesn't pass the--ignoreparam yet. The functions in the CLI package contain some defaults around what is passed toexecute, for example a defaultignore:https://github.com/getsentry/sentry-cli/blob/9f34df859bf2975155aad0fe5c6c423b45c07084/lib/releases/index.ts#L16
The next step is to bring this
injectcommand to the CLI code (CLI PR) so it can be used in the BuildPluginManager.Related to getsentry/sentry-javascript#18519