feat(cli): opt-in crash reporting to Better Stack via Sentry SDK#595
Open
NisargIO wants to merge 1 commit into
Open
feat(cli): opt-in crash reporting to Better Stack via Sentry SDK#595NisargIO wants to merge 1 commit into
NisargIO wants to merge 1 commit into
Conversation
Add strictly opt-in error tracking for the CLI, mirroring the existing opt-in OTLP posture: nothing is sent unless the user sets REACT_DOCTOR_ERROR_REPORTING=1, and @sentry/node is lazy-imported only on that opt-in so the common path pays zero cost. - error-tracking.ts: init (no global handlers, no OTel — the CLI owns its own SIGINT/EPIPE/exit) + captureCliError that flushes before exit. - Capture at every fatal chokepoint: the top-level .catch, the inspect / install command catches, plus new process-level uncaughtException / unhandledRejection safety nets routed through one reportFatalError sink. - Enrich each event with non-source debugging context: origin (handled vs uncaught vs unhandled), command, CI + provider, coding agent, platform, node, TTY, JSON mode, OTLP-configured flags. - Source maps: production build injects debug IDs (sentry-cli sourcemaps inject) and publish.yml uploads matching maps to Better Stack (gated on BETTER_STACK_SOURCEMAP_TOKEN). Maps match by debug ID and stay out of the npm tarball. - @sentry/cli added to onlyBuiltDependencies so its binary postinstall is allowed under pnpm; @sentry/node externalized in the bundle. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
React Doctor found 14 files changed in this pull request, but none matched the files covered by its enabled checks. Scope: 14 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.
Summary
Adds strictly opt-in crash reporting for the
react-doctorCLI to Better Stack (via the Sentry SDK), plus debug-ID source-map upload at publish time so reported stack traces de-minify to the original TypeScript.Mirrors the repo's existing opt-in OTLP posture: nothing is sent unless the user sets
REACT_DOCTOR_ERROR_REPORTING=1, and@sentry/nodeis lazy-imported only on that opt-in, so the common (non-opted-in) run pays zero startup cost and never loads the SDK.What's included
Capture
cli/utils/error-tracking.ts—initErrorTracking()(no global handlers, no OpenTelemetry — the CLI owns its own SIGINT/SIGTERM/EPIPE/exit) +captureCliError()that flushes before the process exits..catch, theinspect/installcommand catches, and new process-leveluncaughtException/unhandledRejectionsafety nets — all routed through a singlereportFatalErrorsink.Context (enriches each event; non-source only — mirrors what the prefilled GitHub issue already exposes)
origin(handledcommandvstop-levelvsuncaughtExceptionvsunhandledRejection),command,ci+ci.provider,coding_agent,json_mode,interactive,node.version,platform,arch.react-doctorcontext block: version, argv, cwd (ENOENT-guarded), runtime, CI/agent, OTLP-configured flags.Source maps
buildrunssentry-cli sourcemaps inject dist, so the shipped bundle carries debug IDs.publish.ymluploads matching maps to Better Stack on both the stable release (gated onoutputs.published) and the dev-snapshot job. Maps match by debug ID and are not shipped in the npm tarball (filesshipsdist/**/*.js, not*.map).@sentry/cliadded to rootonlyBuiltDependencies(binary postinstall under pnpm);@sentry/nodeexternalized in the bundle.BETTER_STACK_SOURCEMAP_TOKENBETTER_STACK_SOURCEMAP_URLhttps://eu-fsn-3-sourcemaps.betterstackdata.com— confirm in dashboard)BETTER_STACK_SOURCEMAP_ORGBETTER_STACK_SOURCEMAP_PROJECT2476923Notes / judgment calls
@sentry/nodev10 pulls in the OpenTelemetry tree (externalized + lazy-loaded, but still installed). Can swap to the lighter@sentry/node-coreif preferred.patch(thefixedgroup would otherwise bump the lint plugins on aminor). Bump tominorif you'd rather mark it a feature.cwdand post-nodeargvare included, consistent withhandle-error.ts's issue template. Easy to drop if you'd rather keep paths out entirely.handleError(styled + prefilled issue URL) and exit 1, instead of Node's raw stack dump.Test plan
typecheck✓,lint✓ (0 errors),format:check✓,build✓ (debug IDs verified in bundle),smoke:json-report✓tests/error-tracking.test.ts(3 cases) mocks@sentry/nodeand asserts the realcaptureCliErrorattaches the expected tags/contexts (local inspect; CI + Claude CodeinstallviauncaughtException; genericCI=true+ OTLP viaunhandledRejection)./tmpcleanup race ininstall-git-hook.test.ts, passes 29/29 in isolation).REACT_DOCTOR_ERROR_REPORTING=1against a run that throws.🤖 Generated with Claude Code