Skip to content

Commit 16eed33

Browse files
Luca Forstnershanamatthewsgetsantry[bot]
authored
Rework sourcemap troubleshooting session for debug IDs (#7049)
Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent 472dd84 commit 16eed33

File tree

5 files changed

+49
-137
lines changed

5 files changed

+49
-137
lines changed
Loading

src/platform-includes/sourcemaps/troubleshooting/javascript.mdx

Lines changed: 34 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,67 @@
1-
Source maps can sometimes be tricky to get going. If you're having trouble, you can try using our verification tool inside `sentry-cli`, or go through the steps listed below yourself. Please keep in mind, that the `sentry-cli` is a work-in-progress, and we're actively working to improve it.
2-
3-
To use the automated verification process, [install and configure](/product/cli/) `sentry-cli`. Once completed, use the `sourcemaps explain` command, by calling it with the event ID that can be found at the top of the **Issue Details** page in [sentry.io](https://sentry.io). For example, "Event fdfd1337e3964cd6a4d11f35357a4c43 | JSON (42.0 KiB)".
4-
5-
```shell
6-
sentry-cli sourcemaps explain fdfd1337e3964cd6a4d11f35357a4c43
7-
```
8-
9-
This should provide you with some useful hints about what exactly went wrong with the source maps setup process.
10-
If it doesn't, let us know so we can make it better.
11-
12-
<PlatformSection notSupported={["javascript.electron"]}>
13-
14-
## Verify a release is configured in your SDK
15-
16-
For uploaded source maps to be located and applied, the release needs to be created by the CLI or API (and the correct artifacts uploaded with it), and the name of that newly-created release needs to be specified in your SDK configuration.
17-
18-
To verify this, open up the issue from the Sentry UI and check if the release is configured. If it says "_not configured_" or "_N/A_" next to **Release** on the right hand side of the screen (or if you do not see a `release` tag in the list of tags), you'll need to go back and [tag your errors](../../configuration/releases/). If this is properly set up you'll see "Release: my_example_release".
19-
20-
</PlatformSection>
21-
22-
## Verify artifacts are uploaded
23-
24-
Once your release is properly configured and issues are tagged, you can find the artifacts uploaded to Sentry by navigating to **[Project] » Project Settings » Source Maps**.
25-
26-
Additionally, make sure all of the necessary files are available. For Sentry to de-minify your stack traces you must provide both the minified files (for example, app.min.js) and the corresponding source maps. In case the source map files do not contain your original source code (`sourcesContent`), you must additionally provide the original source files. Alternatively, sentry-cli will automatically embed the sources (if missing) into your source maps.
27-
28-
## Verify `sourceMappingURL` is present
29-
30-
Some CDNs automatically strip comments from static files, including JavaScript files. This can have the effect of stripping your JavaScript file of its `sourceMappingURL` directive, because it is considered a comment. For example, CloudFlare has a feature called [Auto-Minify](https://blog.cloudflare.com/an-all-new-and-improved-autominify/) which will strip `sourceMappingURL` if it is enabled.
31-
32-
Double-check that your deployed, final JavaScript files have `sourceMappingURL` present.
33-
34-
Alternately, instead of `sourceMappingURL`, you can set a `SourceMap` HTTP header on your minified file. If this header is present, Sentry will use it to discover the location of your source map.
35-
36-
<PlatformSection notSupported={["javascript.electron"]}>
37-
38-
## Verify artifact distribution value matches value configured in your SDK
39-
40-
Whenever you are using a distribution identifier (the `dist` configuration option in the SDK), the same value has to be used during source map upload. Conversely, if your source maps are getting uploaded with a `dist` value, the same value must be set in your SDK.
41-
To add a `dist` value to your uploaded source maps, use the `--dist` flag with `sentry-cli` or the `dist` option in our [Sentry Bundler Plugins](https://github.com/getsentry/sentry-javascript-bundler-plugins) (like for example `@sentry/webpack-plugin`). To set the `dist` value in the SDK, use the `dist` option in your `Sentry.init()`.
42-
43-
To verify that the distribution has been set correctly in the SDK, open an issue in the Sentry UI and check that the `dist` tag is present. For artifacts, go to the `Source Maps` page in project settings, choose the release shown on the event you just checked, and verify that the `dist` value (in the small oval next to the upload time) matches that on the event.
44-
45-
</PlatformSection>
46-
47-
## Verify artifact names match stack trace frames
48-
49-
If you've uploaded source maps and they aren't applying to your code in an issue in Sentry, take a look at the JSON of the event and look for the `abs_path` to see exactly where we're attempting to resolve the file - for example, `http://localhost:8000/scripts/script.js` (`abs_path` will appear once for each frame in the stack trace - match this up with the file(s) that are not deminified.). A link to the JSON view can be found at the top of the issue page next to the date the event occurred. The uploaded artifact names must match these values.
50-
51-
If you have **dynamic values in your path** (for example, `https://www.site.com/{some_value}/scripts/script.js`), you may want to use the <PlatformSection notSupported={["node"]}><PlatformLink to="/configuration/integrations/plugin/#rewriteframes">`rewriteFrames` integration</PlatformLink></PlatformSection><PlatformSection supported={["node"]}><PlatformLink to="/configuration/integrations/pluggable-integrations/#rewriteframes">`rewriteFrames` integration</PlatformLink></PlatformSection> to change your `abs_path` values.
52-
53-
### Using sentry-cli
54-
55-
If your `sourceMappingURL` comment is similar to:
56-
57-
```javascript
58-
// -- end script.min.js (located at http://localhost:8000/scripts/script.min.js)
59-
//# sourceMappingURL=script.min.js.map
60-
```
1+
<Note>
612

62-
An example `sentry-cli` command to upload these files correctly would look like this (assuming you're in the `/scripts` directory, running your web server from one directory higher, which is why we're using the `--url-prefix` option):
3+
If you previously set up source maps, we suggest updating your tools (SDK, bundler plugins, Sentry CLI).
634

64-
```shell
65-
sentry-cli releases files VERSION upload-sourcemaps . --url-prefix '~/scripts'
66-
```
5+
It is generally easier to upgrade to the latest versions and follow the current process rather than troubleshooting with older versions.
676

68-
This command uploads all JavaScript files in the current directory. The Artifacts page in Sentry should now look like:
7+
For information on the legacy method of uploading source maps, please see the guide on <PlatformLink to="/sourcemaps/troubleshooting_js/uploading-without-debug-ids">Uploading without Debug IDs</PlatformLink>.
698

70-
```
71-
~/scripts/script.js
72-
~/scripts/script.min.js
73-
~/scripts/script.min.js.map
74-
```
9+
</Note>
7510

76-
Alternately you can specify which files to upload. For example:
11+
Setting up source maps can be tricky, but it's worth it to get it right. To troubleshoot your source maps set up, you can either:
7712

78-
```
79-
sentry-cli releases files VERSION upload-sourcemaps script.min.js script.min.js.map --url-prefix '~/scripts'
80-
```
13+
1. Use our automated verification tool inside `sentry-cli`, or
14+
2. Follow the manual steps listed below
8115

82-
You can also upload it with the fully qualified URL. For example:
16+
## Use the CLI
8317

84-
```
85-
sentry-cli releases files VERSION upload-sourcemaps . --url-prefix 'http://localhost:8000/scripts'
86-
```
18+
To use the automated verification process, install and configure the Sentry [Command Line Interface](/product/cli/). Then, use the `sourcemaps explain` command, calling it with the relevant event ID, found in the top-left corner of the **Issue Details** page in [sentry.io](https://sentry.io).
8719

88-
### Using the API
20+
For example, "Event ID: c2ad049f":
8921

90-
You can alternately [use our API](/api/releases/update-an-organization-release-file/) to upload artifacts, following the same naming convention explained here.
22+
![Image highlighting where to find the ID of an event on Sentry](event_id.png)
9123

9224
```shell
93-
curl -X POST \
94-
https://sentry.io/api/0/organizations/ORG_SLUG/releases/VERSION/files/ \
95-
-H 'Authorization: Bearer AUTH_TOKEN' \
96-
-H 'content-type: multipart/form-data' \
97-
-F file=@script.min.js.map \
98-
-F 'name=~/scripts/script.min.js.map'
25+
sentry-cli sourcemaps explain c2ad049fd9e448ada7849df94575e019
9926
```
10027

101-
### Using the `~`
102-
103-
The `~` is used in Sentry to replace the scheme and domain. It is not a glob!
104-
105-
`http://example.com/dist/js/script.js` will match `~/dist/js/script.js` or `http://example.com/dist/js/script.js`
106-
107-
but will NOT match `~/script.js`.
28+
The CLI output should give you useful information about what went wrong with your source maps setup.
29+
If it doesn't, let us know by filing an issue on our [Sentry CLI repo](https://github.com/getsentry/sentry-cli) so we can make it better.
10830

109-
## Multiple Origins
31+
## Follow Manual Steps
11032

111-
It's not uncommon for a web application to be accessible at multiple origins. For example:
33+
### Verify Artifacts Are Uploaded
11234

113-
- Website is operable over both `https` and `http`
114-
- Geolocated web addresses: such as `https://us.example.com`, `https://eu.example.com`
115-
- Multiple static CDNs: such as `https://static1.example.com`, `https://static2.example.com`
116-
- Customer-specific domains/subdomains
35+
Verify your artifacts are being uploaded to Sentry. You can find them at **[Settings] > Projects > Select your project > Source Maps**.
36+
For Sentry to de-minify your stack traces you must provide both the minified files (for example, app.min.js) and the corresponding source maps.
11737

118-
In this situation, **identical** JavaScript and source map files may be located at two or more distinct origins. In this situation we recommend using our special tilde (`~`) prefix on paths.
38+
## Verify You Are Building Source Maps
11939

120-
So for example, if you have the following:
40+
Bundlers and tools (like `tsc`) that generate code, often require you to manually set specific options to generate source maps.
12141

122-
- https://static1.example.com/js/app.js
123-
- https://static2.example.com/js/app.js
42+
If you followed one of our tool-specific guides, verify you configured your tool to emit source maps and that the source maps contain your original source code in the `sourcesContent` field.
12443

125-
You can upload using the URL of `~/js/app.js`. This will tell Sentry to ignore the domain and use the artifact for any origin.
44+
## Verify Your Source Files Contain Debug ID Injection Snippets
12645

127-
Additionally you can also upload the same file under multiple names. Under the hood Sentry will deduplicate these.
46+
In the JavaScript files you uploaded to Sentry, search for code that roughly looks like `e._sentryDebugIds=e._sentryDebugIds||{}`. This code snippet might look different depending on how you process your code.
12847

129-
<Note>
130-
131-
The ~ prefix tells Sentry that for a given URL, **any** combination of protocol and hostname whose path is `/js/app.js` should use this artifact. Use this method **only** if your source/source map files are identical at all possible protocol/hostname combinations. **Sentry will prioritize full URLs over tilde prefixed paths**, if found.
132-
133-
</Note>
134-
135-
## Verify artifact names match `sourceMappingURL` value
136-
137-
The `sourceMappingURL` comment on the last line of your bundled or minified JavaScript file tells Sentry (or the browser) where to locate the corresponding source map. This can either be a fully qualified URL, a relative path, or the filename itself. When uploading artifacts to Sentry, you must name your source map files with the value the file resolves to.
138-
139-
That is, if your file is similar to:
48+
If this code exists in a bundle, that bundle will be able to be matched to a source file. Every bundle you deploy in your app needs to have this snippet in order to be correctly source mapped.
14049

141-
```javascript
142-
// -- end script.min.js
143-
//# sourceMappingURL=script.min.js.map
144-
```
50+
If your source code does not contain this snippet and you're using a Sentry plugin for your bundler, please check that you are using the latest version and please verify that the plugin is correctly processing your files. Set the `debug` option to `true` to print useful degbugging information.
14551

146-
and is hosted at http://example.com/js/script.min.js, then Sentry will look for that source map file at http://example.com/js/script.min.js.map. Your uploaded artifact must therefore be named `http://example.com/js/script.min.js.map` (or `~/js/script.min.js.map`).
52+
If you're using the Sentry CLI, verify that you're running the `inject` command **before** you upload to Sentry and **before** you deploy your files.
14753

148-
Or, if your file is similar to:
54+
## Verify Your Source Files Contain Debug ID Injection Snippets
14955

150-
```javascript
151-
//-- end script.min.js
152-
//# sourceMappingURL=https://example.com/dist/js/script.min.js.map
153-
```
56+
When inspecting the event payload JSON data in Sentry, verify that the events have a `debug_meta` property. If this property is missing and you already made sure your source files contain debug ID injection snippets, this likely means that you're using an outdated SDK.
15457

155-
then your uploaded artifact should also be named `https://example.com/dist/js/script.min.js.map` (or `~/dist/js/script.min.js.map`).
58+
We generally recommend upgrading to the latest version, and for source maps to work you need to at least use version `7.47.0`.
15659

157-
Finally, if your file is similar to:
158-
159-
```javascript
160-
//-- end script.min.js
161-
//# sourceMappingURL=../maps/script.min.js.map
162-
```
60+
After you verified your event has a `debug_meta` property, the next thing to check is whether all frames inside the `raw_stacktrace` property inside the events have an `abs_path` property that exactly matches one of the `code_file` properties inside the `debug_meta` images.
16361

164-
then your uploaded artifact should be named `https://example.com/dist/maps/script.min.js.map` (or `~/dist/maps/script.min.js.map`).
62+
If a stack frame doesn't match an entry inside `debug_meta`, make sure that the relevant file contains a debug ID injection snippet.
16563

166-
## Verify artifacts are uploaded before errors occur
64+
## Verify Artifacts Are Uploaded Before Errors Occur
16765

16866
Sentry expects that source code and source maps in a given release are uploaded to Sentry **before** errors occur in that release.
16967

@@ -185,7 +83,7 @@ First, install `source-map` globally as an npm module:
18583
npm install -g source-map
18684
```
18785

188-
Then, write a script that reads your source map file and tests a mapping. Here's an example:
86+
Then, write a Node.js script that reads your source map file and tests a mapping. Here's an example:
18987

19088
```javascript
19189
var fs = require("fs"),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: What are Artifact Bundles
3+
description: "Learn about artifact bundles."
4+
sidebar_order: 6
5+
---
6+
7+
<PlatformContent includePath="sourcemaps/artifact-bundles" />
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Troubleshooting Source Maps
33
description: "Troubleshooting for source maps."
4-
sidebar_order: 8
4+
sidebar_order: 5
55
---
66

77
<PlatformContent includePath="sourcemaps/troubleshooting" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Uploading Without Debug IDs
3+
description: "Learn about uploading source maps without Debug IDs on older SDKs."
4+
sidebar_order: 5
5+
---
6+
7+
<PlatformContent includePath="sourcemaps/uploading-without-debug-ids" />

0 commit comments

Comments
 (0)