Skip to content

CLI Command to inject debug_id for source maps #1467

Description

@lforst

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions