nativescript-community / sentry

A cross-platform application monitoring tool, with a focus on error reporting.
Apache License 2.0
14 stars 6 forks source link

No sourcemap in Sentry #23

Open jerbob92 opened 1 month ago

jerbob92 commented 1 month ago

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 commented 1 month ago

@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 commented 1 month ago

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 commented 1 month ago

I discovered the following:

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 commented 1 month ago

@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 commented 1 month ago

@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 commented 1 month ago

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 commented 1 month ago

@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