Skip to content

feat(worker): add Sentry error tracking and source maps for debuggable builds - #547

Open
realcodesiman wants to merge 1 commit into
mainfrom
feat/improve-debug-build
Open

feat(worker): add Sentry error tracking and source maps for debuggable builds#547
realcodesiman wants to merge 1 commit into
mainfrom
feat/improve-debug-build

Conversation

@realcodesiman

Copy link
Copy Markdown
Contributor

Summary

  • Bundled worker .mjs output is hard to debug: stack traces point at minified-ish bundles, and unhandled errors vanish without a trace in production.
  • Emit source maps and wire Sentry so worker errors remap back to the original TypeScript and get reported centrally — without leaking contact PII or burning Sentry quota during retry storms.
  • Fully opt-in: omitting SENTRY_DSN makes every Sentry helper a no-op.

Changes

  • apps/worker/tsdown.config.ts — emit source maps; add src/instrument.ts as a build entry.
  • apps/worker/src/instrument.ts — initialize Sentry from process.env before any worker module loads; missing DSN disables it.
  • apps/worker/src/lib/sentry.tscaptureException, reportJobFailure (final attempt only, identifiers not raw job.data), flushSentry (best-effort), all guarded by init.
  • apps/worker/src/chat/worker.ts — capture bootstrap failures and report job failures.
  • docker/.../docker-entrypoint.sh — run node with --enable-source-maps --import instrument.mjs, passed directly so a runtime NODE_OPTIONS can't clobber them; validate the instrument script before starting.
  • apps/worker/src/env.ts + .env.example — document/validate SENTRY_* and WORKER_NAME.
  • apps/worker/package.json + pnpm-lock.yaml — add @sentry/node.

Test plan

  • pnpm lint (ran via pre-commit hook)
  • pnpm --filter worker check-types (ran via pre-commit hook)
  • Build worker image and confirm it boots with SENTRY_DSN unset (no-op path)
  • Set a real SENTRY_DSN, force a job failure, confirm event arrives with mapped TS stack trace and no job.data PII

…e builds

Make bundled worker processes debuggable in production by emitting source
maps and wiring Sentry to remap and report errors back to TypeScript sources.

- Emit source maps from tsdown and run node with --enable-source-maps so
  stack traces from bundled .mjs map back to the original .ts
- Initialize Sentry via instrument.ts loaded with node --import, ahead of
  every worker; a missing SENTRY_DSN disables it as a no-op
- Add sentry helpers (captureException, reportJobFailure, flushSentry) that
  guard on init, report only final job attempts, and attach identifiers
  rather than raw job.data to avoid leaking contact PII
- Pass debug/observability flags directly in docker-entrypoint so a runtime
  NODE_OPTIONS cannot clobber them
- Document SENTRY_* and WORKER_NAME in .env.example and validate them in env.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant