Our supports the uploading of source maps, which are used to un-minify error stack traces on the Errors page. This document explains how to use the API to upload source maps using the browser API.
Prepare for using the source map API
In order to upload source maps to browser via the API, you'll need:
Optionally, if the JavaScript URL doesn't automatically have release info appended to it, the release name and ID
Every time the agent captures an error in your code, it's associated with the URL of the JavaScript in which it occurred. This is the src attribute of the script tag in your HTML. This full JavaScript URL is required when sending source maps to browser.
You can find the URL for an error's JavaScript file in browser, on the JS errors page. See Browser monitoring source maps for more on finding these errors in the UI.
Many organizations include a version number or hash in the JavaScript URL. This is generally added to "bust" caches to ensure your users get the most recent version of your code. This type of URL might look something like:
If your app's URLs automatically have the version info appended to it, the browser agent has everything it needs in order to match errors with your code. You can move ahead to generating source maps.
If this doesn't apply to you, and JS URLs do not have version info appended, you’ll have to assist the agent by specifying a release name and ID with the API.
If you're interested in monitoring the performance of your code from your IDE using New Relic CodeStream, repository URL is required. If you'd like to investigate errors from your IDE as well, the build commit hash is recommended, but not required.
Use npm module via command line or client-side script
The easiest and recommended way to upload source maps to browser is to use the our new @newrelic/publish-sourcemap npm module. It provides a command line tool and Javascript API to accomplish this task. More documentation is available in the npm repo.
Here are some examples of using the npm module via the command line.
重要
The following examples are for US accounts. For EU accounts, the endpoint is https://sourcemaps.service.eu.newrelic.com. For more information, see Introduction to the EU region data center.
Here's an example of uploading source maps using the npm module via the command line. Note that the source map can come from a local file or a remote URL.
bash
$
npminstall-g @newrelic/publish-sourcemap
$
publish-sourcemap PATH_TO_SOURCE_MAP_FILE (local or remote) PATH_TO_ORIGINAL_FILE --apiKey=YOUR_NEW_RELIC_USER_KEY --applicationId=YOUR_NEW_RELIC_APP_ID --repoUrl=GITHUB_REPOSITORY_URL --buildCommit=GIT_BUILD_COMMIT_HASH
Here's an example of listing published source maps:
Below is an example of how to get a list of source maps previously uploaded to New Relic via curl. New Relic returns the source map's unique SOURCEMAP_ID and its components:
When you're done, go to the Group errors tab in browser, select an error grouping, and see if your error stack traces have been un-minified.
Troubleshoot source maps
If you are having trouble generating source maps from your build system, or if your errors in browser remain minified, see the source maps troubleshooting documentation.