We want to make source map lookup easier for our users and in the Sentry backend. To accomplish this we want to send debug IDs that point to a particular uploaded source map along with every frame of a stack trace.
The high-level idea is to inject some code into every bundle with sentry-cli that sets a key on a global object mapping from a stack trace to a debug_id. The corresponding source map of that bundle also needs to be given a debug_id field holding the same value. I won't go into specifics about how the code snippet works and how the SDK picks it up because it is not relevant to this task but some more information can be found here and here: getsentry/sentry-javascript#7068
What needs to be done in sentry-cli?
Basically, we just need to port this script from JS to sentry-cli with a separate command (suggestion: sentry-cli sourcemaps inject [paths...]).
High-level overview of what that script does:
- Gets a list of all files that matches
paths (recursively) - Filters that list for
.js files - Reads each JS file
- Looks for a
//# sentryDebugId = comment - If found, ignores a file and emit a warning, that the file was already processed before
- Looks for a
//# sourceMappingURL= comment - If it is not found, ignores the file and emit a warning, that it is missing a source mapping url
- Look for the source map file behind the
sourceMappingURL comment - If it is not found, ignores the file and emit a warning that the corresponding source map couldn't be found
- Generates a random UUID
- Appends the code snippet mentioned above to the JS file and substitute
__SENTRY_DEBUG_ID__ with the generated UUID - Appends a comment "
\n//# sentryDebugId=__SENTRY_DEBUG_ID__" to the JS file and substitute __SENTRY_DEBUG_ID__ with the generated UUID - Reads and parses the corresponding source map.
- Adds a field
debugId to the source map JSON and writes it back to disk. - Done.
We want to make source map lookup easier for our users and in the Sentry backend. To accomplish this we want to send debug IDs that point to a particular uploaded source map along with every frame of a stack trace.
The high-level idea is to inject some code into every bundle with
sentry-clithat sets a key on a global object mapping from a stack trace to adebug_id. The corresponding source map of that bundle also needs to be given adebug_idfield holding the same value. I won't go into specifics about how the code snippet works and how the SDK picks it up because it is not relevant to this task but some more information can be found here and here: getsentry/sentry-javascript#7068What needs to be done in
sentry-cli?Basically, we just need to port this script from JS to
sentry-cliwith a separate command (suggestion:sentry-cli sourcemaps inject [paths...]).High-level overview of what that script does:
paths(recursively).jsfiles//# sentryDebugId =comment//# sourceMappingURL=commentsourceMappingURLcomment__SENTRY_DEBUG_ID__with the generated UUID\n//# sentryDebugId=__SENTRY_DEBUG_ID__" to the JS file and substitute__SENTRY_DEBUG_ID__with the generated UUIDdebugIdto the source map JSON and writes it back to disk.