Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sentry's sourcemaps/artifacts don't work

Tags:

webpack

sentry

I'm building, minifying and generating sourcemaps of my app with webpack. Artifacts are sent to sentry.io with webpack-sentry-plugin.

The javascript code is run from localhost:8080/js/app.js. It contains //# sourceMappingURL=app.js.map at the end. Sourcemaps work correctly at Chrome devtools.

Sentry's Releases/Artifacts contain the following files:

js/app.js
js/app.js.map

Anyway, when Sentry logs an error, stacktrace is from the minified file. It's not using the sourcemaps.

What am I doing wrong in my setup? Or what other info should I give to get help?

like image 566
gustavopch Avatar asked Feb 07 '17 12:02

gustavopch


People also ask

How do you fix a source map error?

The only workaround is to manually change the map URL to a public one (http://localhost:1234/file.map.js) and start a local webserver at this port.

How do Webpack Sourcemaps work?

Webpack bundles multiple source files to one single bundle file. In some cases, there can be multiple bundle files. But in both cases, if there is an error in one of the source files, it is difficult to track it down from browser console. Source maps connect the bundle file with corresponding source files.

What is SourceMap in sentry?

Sentry supports demangling of transpiled, minified, and bundled JavaScript using source maps, which are JSON files that contain information about how to map your deployed code back to its original source(s). This lets you view source code context obtained from stack traces in its original, untransformed form.

What is Sourcemappingurl?

The SourceMap HTTP response header links generated code to a source map, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger.


1 Answers

I posted this question at forum.sentry.io and got the answer from a guy called @benvinegar.

Here is the thing: when sending a sourcemap/artifact, we provide the file and also a filename. The filename is meant to be the complete URL where the sourcemap would be located if it was uploaded to the host together with the minified JS files. That is: if our minified Javascript is located at www.example.com/js/app.js, then the sourcemap/artifact filename must be www.example.com/js/app.js.map. Otherwise, we can name it ~/js/app.js.map if we want the sourcemap to apply to other situations like running the app at localhost:8080/js/app.js.

As I'm using webpack-sentry-plugin, it was just a matter of adding the following property to the plugin:

{
  plugins: [
    new SentryPlugin({
      filenameTransform: filename => '~/' + filename
    })
  ]
}
like image 172
gustavopch Avatar answered Nov 15 '22 06:11

gustavopch