feat(cli): symbolicate Sentry crash traces via runtime sourcemaps#626
Closed
NisargIO wants to merge 1 commit into
Closed
feat(cli): symbolicate Sentry crash traces via runtime sourcemaps#626NisargIO wants to merge 1 commit into
NisargIO wants to merge 1 commit into
Conversation
Emit an external sourcemap for the CLI bundle and turn on Node's source-map support in the bin shim, so uncaught errors captured by Sentry resolve to original-TypeScript positions instead of bundled dist/cli.js offsets. - vite.config.ts: `sourcemap: true` on the CLI pack entry only — the API entry stays map-free; it never initializes Sentry. - package.json: ship `dist/**/*.js.map` in the published tarball. - bin/react-doctor.js: `process.setSourceMapsEnabled(true)` before the `dist/cli.js` import. It must precede compile — Node caches a module's sourcemap at compile time, so enabling it from inside the already-loaded bundle is too late for the bundle's own frames. Guarded like `enableCompileCache` so a runtime without the API can't crash the CLI. The map is external (not inlined) and read lazily by Node only when a stack is materialized, so the no-crash path has no startup cost. Symbolication happens on-device; no upload step. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
commit: |
Contributor
|
React Doctor found 4 files changed in this pull request, but none matched the files covered by its enabled checks. Scope: 4 files changed on Generated by React Doctor. Questions? Contact founders@million.dev. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cc @rayhanadev
What
Crash reports added in #621 currently land in Sentry with frames pointing at the bundled
dist/cli.js(offsets likecli.js:1:48572), which aren't triage-able. This wires up on-device sourcemap symbolication so traces resolve to original-TypeScript positions (src/cli/...ts:line:col).How
vite.config.tssourcemap: trueon the CLI pack entry only → emitsdist/cli.js.map+ asourceMappingURLcomment. The API entry stays map-free (it never initializes Sentry).package.jsondist/**/*.js.maptofilesso the map ships in the npm tarball.bin/react-doctor.jsprocess.setSourceMapsEnabled(true)before theimport, so Node rewritesError.stackto original positions before@sentry/nodereads it..changeset/cli-sourcemaps.mdpatchbump.Why the bin shim, and why before the import
setSourceMapsEnabledis a process-global switch, and Node caches a module's sourcemap at compile time — so it must be flipped on beforedist/cli.jsis compiled by theimport(). Putting it inside the bundled TS would be too late for the bundle's own frames. Verified empirically (enable-before → frame maps to source; enable-after → frame stays on the bundled file). The call is guarded likeenableCompileCacheso an exotic/old runtime can't crash the CLI for the sake of an observability nicety.Tradeoffs
dist/cli.jslean; Node reads the map lazily, only when a stack is materialized (i.e. on a crash), so the no-crash path has zero added startup cost..tsfiles aren't shipped. Frame paths will include the user's local install path, consistent with the existingsendDefaultPii: trueposture.Testing
pnpm buildemitsdist/cli.js.map+ thesourceMappingURLcomment, then triggering a deliberate throw to eyeball a symbolicated Sentry event before relying on it.🤖 Generated with Claude Code