|
| 1 | +--- |
| 2 | +title: What are Debug IDs |
| 3 | +sidebar_order: 7 |
| 4 | +--- |
| 5 | + |
| 6 | +This documentation provides an in-depth look at Debug IDs, explaining how they work and why Sentry recommends using them. Visit [Uploading Source Maps](https://docs.sentry.io/platforms/javascript/guides/react/sourcemaps/uploading/) if you're looking for our guides on how to upload source maps. |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +Developers of modern websites often use some kind of build process when they add JavaScript to the site. This build process takes some input JavaScript, transforms it in some way, then outputs JavaScript that is served alongside the website. Some example transformations include minifying JavaScript code (so the final JavaScript bundle is smaller and faster to load) or removing TypeScript types (only JavaScript can run on the browser). |
| 11 | + |
| 12 | +As a result, the JavaScript code running in production is typically not the same as the code written by the developer in the source editor. Instead, it has undergone several transformations, such as [minification](https://developer.mozilla.org/en-US/docs/Glossary/Minification), [transpilation](https://www.typescriptlang.org/), [downcompilation](https://babeljs.io/), [transformation](https://rollupjs.org/), [polyfilling](https://developer.mozilla.org/en-US/docs/Glossary/Polyfill), and others, aimed at improving performance and ensuring cross-browser compatibility. |
| 13 | + |
| 14 | +Stack traces are essential to debug errors, but stack traces that come from generated JavaScript are often unreadable or unusable! They look nothing like the code you wrote, you can’t connect them to your source code repository, and minified variables or function names make you lose context about what is happening. |
| 15 | + |
| 16 | +To ensure Sentry (and other tools) can provide stack traces that are both readable and useful, you’ll want to generate and use [source maps](https://firefox-source-docs.mozilla.org/devtools-user/debugger/how_to/use_a_source_map/index.html). Source maps are files that map the transformed JavaScript back to the original code. This allows Sentry to trace the error to your original source, which means you’ll get stack traces that look like the code you wrote, not the code you generated. |
| 17 | + |
| 18 | +To connect source maps to a JavaScript file, we relied on filenames, but these often were unreliable. For example, a new deploy of a source map with the same filename would mean the source mapping gets incorrectly applied. |
| 19 | + |
| 20 | +`//# source mappingURL=http://example.com/path/to/your/source map.map` |
| 21 | + |
| 22 | +Given the url-based filename approach was unreliable, we came up with [Debug IDs](/platforms/javascript/sourcemaps/debug-ids#what-is-a-debug-id). |
| 23 | + |
| 24 | +## What are Debug IDs |
| 25 | + |
| 26 | +Inspired by approaches in native language ecosystems, Debug IDs are globally unique ids that identify a transformed JavaScript file and its associated source map. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +When using sentry-cli or bundler plugins for Webpack, Vite, or Rollup, Debug IDs are deterministically generated based on the source file contents. Note that deterministic Debug IDs for esbuild are not currently supported. |
| 31 | + |
| 32 | +This approach is Sentry's recommended and most reliable method for associating minified JavaScript files with their original source code, making it easier to trace errors back to their source. As a result, **creating a release is no longer required**. |
| 33 | + |
| 34 | +<Alert> |
| 35 | + |
| 36 | +If you want to learn more about the rationale behind Debug IDs, we suggest taking a look at our [engineering blog](https://sentry.engineering/blog/the-case-for-debug-ids). |
| 37 | + |
| 38 | +</Alert> |
| 39 | + |
| 40 | +## How Sentry uses Debug IDs |
| 41 | + |
| 42 | +To use Debug IDs, you need **version 7.47** or higher of one of our [JavaScript SDKs](https://github.com/getsentry/sentry-javascript). Once you're using a supported SDK, the process works as follows: |
| 43 | + |
| 44 | +1. **A globally unique Debug ID is generated**: During the build process a Debug ID is generated, which is globally unique and ideally deterministic (typically a UUID). |
| 45 | + |
| 46 | +2. **Debug IDs are embedded in minified files**: Each minified JavaScript file includes a special comment, such as `//# debugId=DEBUG_ID`, where `DEBUG_ID` is the unique identifier generated in the previous step. |
| 47 | + |
| 48 | +3. **The same Debug ID is added to source maps**: Source maps also include the same Debug ID as a new attribute, linking the minified JavaScript file to its corresponding source map. |
| 49 | + |
| 50 | +4. **Stack traces in Sentry link the Debug ID**: When an error occurs, Sentry's event contains the Debug ID, which allows Sentry to automatically link the error to the correct source map. This ensures the stack trace is resolved back to the original source code, providing you with clearer and more accurate debugging information—even if the JavaScript has been minified or transformed. |
| 51 | + |
| 52 | +### Why use Debug IDs to uniminify your code? |
| 53 | + |
| 54 | +Unminifying your code is essential for effective debugging. While there are other [legacy ways](https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/legacy-uploading-methods/) to achieve this at Sentry, using **Debug IDs are recommended by Sentry** as it is the most reliable and deterministic method. By unminifying your code, you get much clearer stack traces when errors occur. Instead of seeing obfuscated code, you'll see the exact code you originally wrote, making it far easier to understand and resolve issues. Below are examples that demonstrates the difference: |
| 55 | + |
| 56 | +#### Bad Stack Trace |
| 57 | + |
| 58 | + |
| 59 | +#### Good Stack Trace |
| 60 | + |
| 61 | + |
| 62 | +## Retention Policy |
| 63 | + |
| 64 | +Debug IDs have a retention period of _90 days_, using a _time to idle_ expiration mechanism. |
| 65 | +This means that uploaded Debug IDs are retained for as long as they are actively being used for event processing. |
| 66 | +Once an id has not been used to process incoming events for at least 90 days, it will automatically expire and be eligible for deletion. |
| 67 | + |
| 68 | +## Associating a Release with Debug IDs |
| 69 | + |
| 70 | +Since you might still want to know to which release an specific Debug ID is connected to, we designed a new way to still associate a `release` to your bundle. |
| 71 | + |
| 72 | +The new Debug ID format supports a new kind of association to a `release` and optionally `dist`, known as weak release association. This type of association **will not require the creation of a `release`** before uploading source maps and will consequently allow the creation of a `release` as a separate step down the pipeline. |
| 73 | + |
| 74 | +With an associated `release` and optionally `dist` you will be able to quickly go to the Debug ID from your `release` in Sentry, without having to worry about which Debug ID was used for your errors. |
0 commit comments