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

No sourcemap in Sentry #23

Open
jerbob92 opened this issue Jun 20, 2024 · 7 comments
Open

No sourcemap in Sentry #23

jerbob92 opened this issue Jun 20, 2024 · 7 comments

Comments

@jerbob92
Copy link

jerbob92 commented Jun 20, 2024

I followed the readme closely (but had to make changes to make it work in the current NS setup), but I can't get sourcemaps to show up in Sentry. I'm 100% certain the source maps are uploaded (I validated in Sentry), and I'm also 100% sure that the release and dist in the Webpack sentryWebpackPlugin match up with what I configure in the plugin.

But it still ends up like this in Sentry:

image

Any idea what I can do here? I also tried with and without rewriting. My webpack looks like this now:

    if (env.uploadSourceMap) {
        webpack.chainWebpack((config) => {
            config.devtool = false;

            // Write away sourcemaps outside build dir.
            const customSourceMapDevToolPluginInstance = new SourceMapDevToolPlugin({
                append: `\n//# sourceMappingURL=[name].js.map`,
                filename: '../../../../../../sourceMap/[name].js.map'
            });
            config.plugin('SourceMapDevToolPlugin').use(customSourceMapDevToolPluginInstance);

            const customSentryWebpackPluginInstance = sentryWebpackPlugin({
                rewrite: true,
                release: {
                    name: `${appID}@${appVersion}+${buildNumber}`,
                    dist: `${buildNumber}.${platform}`,
                    setCommits: {
                        auto: true
                    }
                },
                ignoreFile: '.sentrycliignore',
                include: [join(__dirname, `platforms/sourceMap`)],
                telemetry: false
            });

            config.plugin('sentryWebpackPlugin').use(customSentryWebpackPluginInstance);
        });
    }
@farfromrefug
Copy link
Member

@jerbob92 cant really say why it does not work in your case.
Here is a an example which is working with my self hosted sentry https://github.com/Akylas/OSS-DocumentScanner/blob/master/app.webpack.config.js#L556

@jerbob92
Copy link
Author

jerbob92 commented Jun 20, 2024

Thanks! I think that did give me some hints, it also seems like I was wrong in what it uploads, it only seems to upload the JS right now, not the source map. I think it's not able to resolve the sourcemaps right now because I have them placed in a different directory, with the sourcemaps option that should be fixed :)

@jerbob92
Copy link
Author

I discovered the following:

  • With assets you're only supposed to give js files, not the sourcemaps
  • The plugin will only detect the sourcemaps if they are in the same folder as the source file, or if the path in sourceMappingURL is absolute
  • If you do not want to publish the sourcemap, you don't want them in the build ofcourse, so you would use filesToDeleteAfterUpload, but for some reason that breaks the plugin (maybe it needs the files after deleting?)

So my current solution is:

            const sourcemapDir = join(__dirname, `platforms/sourceMap`);

            // Write away sourcemaps outside build dir.
            const customSourceMapDevToolPluginInstance = new SourceMapDevToolPlugin({
                append: `\n//# sourceMappingURL=${sourcemapDir}/[name].js.map`,
                filename: '../../../../../../sourceMap/[name].js.map'
            });
            config.plugin('SourceMapDevToolPlugin').use(customSourceMapDevToolPluginInstance);

And then not setting any assets. This will keep the sourcemap out of the build (will be in platforms/sourceMap and still allows the plugin to resolve them.

I did notice that the source mapping won't work correctly for captureMessage, but it does for normal errors.

@farfromrefug
Copy link
Member

@jerbob92 if it works for you good. Now I can way in my apps it works as expected even if the sourcemaps are not in the same folder. Not sure what the difference might come from.
I using latest sentry self hosted

@jerbob92
Copy link
Author

jerbob92 commented Jun 21, 2024

@farfromrefug but in your linked example it does put the source map in the same dir as the JS, so probably they do end up in the app build. I also use latest self-hosted Sentry.

@jerbob92
Copy link
Author

jerbob92 commented Jun 21, 2024

This is the final issue I'm trying to solve:

Sentry.captureMessage:
image

As you can see, this doesn't have the sourcemap, probably because the stack is incorrect?

Capturing exceptions (just a random throw somewhere) with a custom Angular ErrorHandler:
image

This one has a stack but it has the stack of where I execute Sentry.captureException. Any idea what I can do to improve this? I would expect it to take the stack of the err object.

@farfromrefug
Copy link
Member

@jerbob92 it must come from the stack "filename" format. hard to say without being in front. But same the sample code i shared works for ios/android so you can look at it.
Maybe this could be important too https://github.com/Akylas/OSS-DocumentScanner/blob/master/app/utils/sentry.ts#L17

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

No branches or pull requests

2 participants