Some of the most common questions we get here at Rollbar deal with source maps:
- What are source maps and what do they do?
- How can you enable source mapping?
- Why aren't your source maps working properly?
If Rollbar receives an occurrence with certain keys set in it, we will use any source maps that you have provided to us to decode your stack trace. The values that need to be set in your configuration are as follows:
You have two options for providing your source map files to Rollbar: automatic download, or uploading your source maps. We recommend uploading your source map files, and you have two options for how to do this. One is to manually upload your source maps through our UI. Go to your project settings page, and click Source Maps. There, you'll be able to manually select the file you wish to upload. However, our recommended way to upload your source map files is to upload via our API at the beginning of your deploy script (before the new code is in production). Here's an example cURL command for how to do this:
curl https://api.rollbar.com/api/1/sourcemap \ -F access_token=aaaabbbbccccddddeeeeffff00001111 \ -F version=version_string_here \ -F minified_url=http://example.com/static/js/example.min.js \ -F source_map=@static/js/example.min.map \ -F static/js/site.js=@static/js/site.js \ -F static/js/util.js=@static/js/util.js
In the above example, our website is
http://example.com/js/example.min.js, and we have a source tree like this:
example/ example/static/js/example.min.js example/static/js/example.min.map example/static/js/site.js example/static/js/util.js
sourceMappingUrl comment. If it has one, we'll try to download that file and save it as the source map. Then for future errors, we'll use the source map to translate the minified frames back to original frames. This is the easiest method, but not suitable for all cases (such as if you don't want to expose your source map or code to the public web). It is also less reliable than the upload method, since the source map won't be downloaded yet when the first few errors come in. Because of this, we recommend the upload method for production use.
However, if you're using the automatic download method, you can notify our API to trigger a download for each of your minified files. Doing this will reduce the number of errors that the source map isn't applied to, since we'll have a greater chance of downloading the source map before the first error after a deploy occurs. Here's a sample command for this:
curl https://api.rollbar.com/api/1/sourcemap/download -F access_token=aaaabbbbccccddddeeeeffff00001111 \ -F version=92429d82a41e930486c6de5ebda9602d55c39986 \ -F minified_url=http://example.com/static/js/example.min.js
Tips and tricks for using source maps with Rollbar
This all seems simple enough, but there are some common problems our users have run into.
- The value of
minified_urlmust be the full URL of the minified file. This should start with
https:, which we'll strip off.
- If you're using the upload method, check to be sure that the
code_versionused in the on-page snippet matches the version provided in the upload call.
guess_uncaught_frames, we won't be able to apply the source map. We need column numbers to be able to apply the source map without guessing.
- If your source map file combines multiple sub-maps into "sections" within the top level map, we unfortunately don't yet support this source map format (but we are planning to soon).
May all your errors be easy to fix, and if you run into any issues, feel free to contact Customer Support.