Sourcemaps

Sourcemaps are a way to convert (minified) JavaScript backtraces such as https://your.host/application-minified.js:53:9895 to something a bit more helpful. A sourcemap contains data about your front-end source code and given the minified file, line number and column number, we can ask a sourcemap for the original function, line/column number and even surrounding source code.

Requirements

Enhancing backtraces with sourcemaps has one requirement:

  • Each sample needs to tagged with a revision of your application. This is used to determine when to fetch new sourcemaps after a deploy has changed your (front-end) code. You can specify the revision in the options given when creating a new AppSignal instance.
javascript
const appsignal = new Appsignal({ key: "<your frontend API key>", revision: "<your current revision>", });

Public sourcemaps

With public sourcemaps the sourcemap is hosted next to the (minified) JavaScript file. At the bottom of the minified JavaScript there needs to be a special comment to indicate that a sourcemap is available for the code.

javascript
//# sourceMappingURL=file.js.map

The URL in this comment can either be a full URL or a relative path to the sourcemap. If the URL is relative, we use the file path of the minified source to determine a full URL.

For example, if the minified JS is hosted on: https://your.app/assets/application.min.js and the sourcemap comment looks like //# sourceMappingURL=application.js.map, we will attempt to retrieve the source map from the following URL: https://your.app/assets/application.js.map.

Our system has limited caching of public sourcemaps, this means that we can request the minified version and the sourcemap file multiple times after a deploy.

Private sourcemaps

When you don't want to make your sourcemap public, you can upload them to our sourcemaps API endpoint.

Sending sourcemaps

A CURL command would look like this:

bash
curl -k -X POST -H 'Content-Type: multipart/form-data' \ -F 'name[]=https://test.local/main.abc123.js' \ -F 'revision=abcdef' \ -F 'file=@/~project/main.js.map' \ 'https://appsignal.com/api/sourcemaps?push_api_key=xxx&app_name=AppSignal&environment=development'

We match the name[] fields against the full backtrace url e.g. the following backtrace line:

shell
at https://test.local/main.abc123.js:1:92623\"

Will match with the name: https://test.local/main.abc123.js. You can add multiple name's in one curl request:

bash
curl -k -X POST -H 'Content-Type: multipart/form-data' \ -F 'name[]=https://test.local/main.abc123.js' \ -F 'name[]=https://cdn.local/main.abc123.js' \ -F 'revision=abcdef' \ -F 'file=@/~project/main.js.map' \ 'https://appsignal.com/api/sourcemaps?push_api_key=xxx&app_name=AppSignal&environment=development'

You can read more about the sourcemap API endpoint on the documentation page.

NOTE: You can only upload one sourcemap file at a time, so if you have multiple sourcemap files, you will have to send an upload request for each file separately. Maximum upload size allowed for sourcemap file is 100MB.

Retention

Sourcemaps are grouped into a "release" by the revision string and we will keep the last "release" until a new revision is uploaded. Older "releases" will be kept for up to sixty days.