sentry-javascript: Followed source map instructions, but line numbers are wrong, etc

Package + Version

  • @sentry/node - 5.18.1
  • @sentry/integrations - 5.18.1
  • @sentry/webpack-plugin - 1.11.1

Description

I’ve followed the instructions on source maps to the best of my knowledge. I’m trying this out with a Serverless Framework setup.

It’s quite an improvement over how reporting looked before I followed the steps, but the line number is totally wrong and the module name is missing. There’s also still remnants of webpack variable names.

https://sentry.io/organizations/reelcrafter/issues/1749922899/?project=5298557

Screen Shot 2020-06-27 at 6 19 00 PM

webpack.config.js

const path = require("path");
// eslint-disable-next-line import/no-unresolved
const slsw = require("serverless-webpack");
const SentryPlugin = require("@sentry/webpack-plugin");

module.exports = {
  entry: slsw.lib.entries,
  devtool: "source-map",
  output: {
    libraryTarget: "commonjs",
    filename: "[name].js",
    path: path.join(__dirname, ".webpack"),
  },
  mode: "development",
  target: "node",
  module: {
    rules: [
      {
        test: /\.js$/, // include .js files
        enforce: "pre", // preload the jshint loader
        exclude: /node_modules/, // exclude any and all files in the node_modules folder
        include: __dirname,
        use: [
          {
            loader: "babel-loader",
          },
        ],
      },
    ],
  },
  plugins: [
    new SentryPlugin({
      release: process.env.RELEASE,
      include: "./.webpack",
    }),
  ],
};

test.js

import * as Sentry from "@sentry/node";
import { RewriteFrames } from "@sentry/integrations";

Sentry.init({
  dsn: "https://xx",
  release: process.env.RELEASE,
  integrations: [new RewriteFrames()],
});

/**
 ...
*/

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (9 by maintainers)

Most upvoted comments

WARNING in configuration. The ‘mode’ option has not been set, webpack will fallback to ‘production’ for this value. Set ‘mode’ option to ‘development’ or ‘production’ to enable defaults for each environment.

😶

I found the main issue. It’s TerserPlugin messing around with the source code.

optimization: {
  minimize: false,
},

Add this to your webpack config and you should be good no matter what mode is set! (this is the only change I did base on your current repo state).

You can play around with TerserPlugin default options to find which exactly is the culprit if you want to use it nonetheless - https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions

BTW, I appreciate all your time and help! Don’t worry, I’m a paid Sentry customer. 😆

Anytime, I’m curious myself what’s going in here 😄

For anyone who might still have problems with the source map line numbers while using Terser plugin, I could get it working properly by disabling the following compress options in terserOptions:

compress: {
  conditionals: false,
  sequences: false
}

Ahh, I just figured out why this solution was working fine on my test project, but not an actual real project!

In my real project, all my code is under src/. So I had to change the include in the webpack.config.js:

    new SentryPlugin({
      release: process.env.SENTRY_RELEASE,
      include: "./.webpack/service/src",
    }),

When it was just include: "./.webpack/service",, the source maps were way off.

@ffxsam I was struggling with this issue as well for a while. A few weeks ago I wrote an article on how to make it work. Maybe it helps you: Fix sentry sourcemaps in AWS lambda functions

TLDR:

  • package functions individually
  • prefix the file name with the function name in stacktraces so it will match the sls webpack structure that has been uploaded to sentry with a release

@ffxsam you forgot to import basename method from builtin path package 😅 I’ll take a look at the rest of the code tomorrow and get back to you.