-
-
Notifications
You must be signed in to change notification settings - Fork 133
Sourcemaps were uploaded but Sentry displays only generated JavaScript code #435
Description
Since I can't get Sentry/Raven work with TypeScript on NodeJS, I decided to create a small testproject. The progress is now that uploading sourcemaps to Sentry seems to work. At least the Releases tab show me that we have the main js file generated by Webpack and the corresponding sourcemap as you can see here:
But it appears that those sourcemap is never used by Sentry. After provoking an exception, it shows me only the generated js:
According to the ts source code, we see that TypeScript -stuff like the interface or strongly typed parameters are missing. This would be even more clear if the target in tsconfig.json is changed from es6 (default in raven-node TypeScript documentation) to the old es5. Now we see more ugly prototype definitions or pseudo-classes created by functions, which doesn't exist in Typescript:
Strange is, that sentry say the error happens in index.ts
as you can see at the headline of the issue:
But in the exception it refers to dist/main.js
as you can see in the other screenshot above.
UPDATE Found out that there's another way how we can easily see that sourcemaps doesn't work. Simply run webpack in production mode (In my case, I changed this in package.json
). Sentry displays the messy minified code:
What exactly did I do?
For this test-case, I used the official documentations how to use raven-node together with Typescript:
- https://docs.sentry.io/clients/node/config/
- https://docs.sentry.io/clients/node/typescript/
- https://docs.sentry.io/clients/node/sourcemaps/#raven-node-sourcemaps
- https://docs.sentry.io/learn/cli/configuration/#properties-files
According to the docs, a new project was created to make sure, that nothing of the existing stuff in my project cause trouble, which prevent Sentry from work correctly. Altogether, about one day was spend on this topic by me. Now a point is reached, where I think this is a bug, when it doesn't work on a new project as expected.
The test project was launched with the following command:
export RELEASE=0.4 && npm run build && npm start
Environment
I used a local installation of sentry 8.22 on Docker. It runs a main sentry server (default entrypoint), a cron (sentry run cron
) and one worker (sentry run worker
). All use the same sentry:8.22
image. The database is a postgres-container, like recommended in the installation-guide.
Configuration of my testproject
src/index.ts
import * as Raven from 'raven'
import * as path from 'path'
import { env } from 'process'
declare global {
namespace NodeJS {
interface Global {
__rootdir__: string;
}
}
}
global.__rootdir__ = __dirname || process.cwd();
const root = global.__rootdir__;
console.log(`Release: ${process.env.RELEASE}`)
let options = {
release: process.env.RELEASE,
dataCallback: function (data) {
var stacktrace = data.exception && data.exception[0].stacktrace;
if (stacktrace && stacktrace.frames) {
stacktrace.frames.forEach(function (frame) {
let old = frame.filename
if (frame.filename.startsWith('/')) {
frame.filename = "app:///" + path.relative(root, frame.filename);
}
});
}
return data;
}
}
let dn = 'http://<xyz>@<host>:9000/2'
Raven.config(dn, options).install();
interface Test {
name: string
}
class TestClass {
testVar = 1
foo(bar: string, test: Test) {
console.log(test.name)
throw new Error('foo called with bar = ' + bar)
}
}
let test = new TestClass()
let testInterface: Test = { name: 'abc' }
test.foo('Test', testInterface)
tsconfig.json
For simplicity, I combined tsconfig.json
and tsconfig.production.json
, which are divided in the documentation. Shouldn't make a difference since the production config inherit from the base one.
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"allowJs": true,
"moduleResolution": "node",
"outDir": "dist",
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/"
},
"include": [
"./src/**/*"
]
}
webpack.config.json
const path = require('path')
const fs = require('fs')
const SentryPlugin = require('@sentry/webpack-plugin')
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function (x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function (mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
module.exports = {
entry: './src/index.ts',
target: 'node',
externals: nodeModules,
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
// https://github.com/getsentry/sentry-webpack-plugin
new SentryPlugin({
organization: '',
release: process.env.RELEASE,
mode: 'development',
configFile: 'sentry.properties',
include: './dist',
ignore: ['node_modules', 'webpack.config.js'],
})
]
};
sentry.properties
This is for the sentry-cli, which is used internally by the webpack plugin. auth.token
has project.write
permission, see Uploading Source Maps to Sentry in the docs.
defaults.url=http://<sentryhost>:9000
defaults.org=test
defaults.project=nodejs-test
# Generated by http://>sentryhost>:9000/api/
auth.token=3046b4383db1436ab6c132b16e8b4995be68a40a6f654686937a2b18c1521911
package.json
{
"name": "sentry-test-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --mode development",
"start": "node dist/main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"raven": "^2.4.2",
"typescript": "^2.7.2"
},
"devDependencies": {
"@sentry/webpack-plugin": "^1.3.3",
"@types/node": "^9.4.6",
"@types/raven": "^2.1.5",
"ts-loader": "^4.0.1",
"webpack": "^4.0.1",
"webpack-cli": "^2.0.10"
}
}