Skip to content

Add Sentry Bun SDK for error and performance monitoring - #13

Open
macuzi wants to merge 1 commit into
mainfrom
macuzi/install-sentry-bun-sdk
Open

Add Sentry Bun SDK for error and performance monitoring#13
macuzi wants to merge 1 commit into
mainfrom
macuzi/install-sentry-bun-sdk

Conversation

@macuzi

@macuzi macuzi commented Jul 27, 2026

Copy link
Copy Markdown
Owner

What

Installs and wires up @sentry/bun for error and performance monitoring across both process entry points (the brenda CLI and the index-sources script).

Changes

  • src/instrument.ts (new) — shared initSentry() that reads the DSN only from SENTRY_DSN and no-ops when unset. Self-initializes on import.
  • src/cli/index.ts / scripts/index-sources.tsimport the instrument module first, before any other module (ES imports are hoisted, so import order is what guarantees Sentry initializes before instrumented code loads — the canonical Sentry ESM pattern).
  • src/cli/commands/ask.ts / scripts/index-sources.tscaptureException + Sentry.flush(2000) before process.exit(1), since the SDK's global handlers never see swallowed errors and the process exits too fast for the background transport otherwise.
  • .env.example — documents SENTRY_DSN= (empty) and SENTRY_ENVIRONMENT.

Key decisions

  • DSN is env-only, no hardcoded fallback. This repo is public; a committed DSN could be abused to spam the project's event quota. The real DSN lives only in the local (gitignored) .env.
  • compare.ts left alone — its process.exit(1) paths are all expected user-input validation (bad hex), which would be noise. Genuine runtime errors there are still caught by the global handlers Sentry.init() installs.
  • @sentry/bun (not @sentry/node) — the app runs on the Bun runtime; the Bun SDK instruments Bun's native APIs and installs global error handlers automatically.

Verification

  • bun test — 9 pass, 0 fail
  • With SENTRY_DSN set → Sentry client is active; without it → no client (no-op, app runs normally)
  • brenda --help starts cleanly (no startup regression)

To activate

Add a DSN to .env:

SENTRY_DSN=https://<your-dsn>@<org>.ingest.us.sentry.io/<project>

🤖 Generated with Claude Code

Initialize Sentry via a shared src/instrument.ts imported first in both
process entry points (the CLI and the index-sources script). The DSN is
read only from SENTRY_DSN and no-ops when unset, so the DSN never lives
in source and the app runs normally without it.

Capture and flush caught errors before process.exit in the ask command
and indexing script, since the SDK's global handlers never see them and
the process exits too fast for the background transport otherwise.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant