The following steps will configure your JS application to automatically upload sourcemap files upon project build, as well as configure your Backtrace client to set the appropriate ID to match your errors with the appropriate sourcemap files.
1. Generate source maps for your application
This step is application-specific. Make a note of your build folder location, you’ll need it for step 4 below.
2. Install backtrace-sourcemap-tools as a dev dependency
npm install "git@github.com:backtrace-labs/backtrace-sourcemap-tools.git" --save-dev
or in package.json:
"devDependencies": {
"backtrace-sourcemap-tools": "git@github.com:backtrace-labs/backtrace-sourcemap-tools.git"
}
3. Configure sourcemap upload url in package.json
This specifies the url, token, and universe that Backtrace sourcemap tools will upload sourcemap files to when your project is built.
Add backtrace as a top-level key in your package.json with the following contents - You need to specify your universe name, project name, and symbol upload token. (Note that this token is different from your error submission token - it’s generated in your Project Settings | Symbols section)
"backtrace": {
"sourcemap": {
"upload": "https://<universe>.sp.backtrace.io:6098/post?format=sourcemap&token=<token>"
},
(For on-premise Backtrace servers, replace <universe>.sp.backtrace.io:6098 with the server and port of your Backtrace instance)
4. Set up automatic sourcemap uploads
This method will upload all artifact .map files.
First, in your package.json’s scripts/build command, append npm run upload
Finally, add action scripts/upload to run backtrace-sourcemap with package.json and the build folder as parameters. In this example, package.json and the dist folder are both in the project root.
"build": "my current build command && npm run upload",
"upload": "./node_modules/.bin/backtrace-sourcemap upload package.json dist",
5. Set up automatic uuid generation in backtrace-node or backtrace-js:
To match a sourcemap file with an error report, a uuid is generated and attached to both the sourcemap file and the outgoing crash report.
Call client.setSymbolication() in your Backtrace client initialization code to enable this.
var client = bt.initialize({
endpoint: '...',
token: '...'
});
client.setSymbolication(); // this line enables automatic UUID generation