# error-reporting

Sentry SDK setup for the Worker, the browser and the Expo app, with one scrubber, off without a DSN.

## Purpose [#purpose]

The only place that imports Sentry's SDKs (`pnpm lint` enforces it). It configures `@sentry/cloudflare` and `@sentry/browser` (v11, restricted `dataCollection`) and `@sentry/react-native` (v10 through its pinned core, `sendDefaultPii: false`), passes every event and breadcrumb through `scrub.ts`, and sends errors only. Each runtime is off until its DSN is set. The browser posts to the Worker's tunnel and the Expo app, native crash reports included, to the Worker's relay (`POST /api/<project id>/envelope/`), never to the tracker; the relay scrubs native events, which never ran `beforeSend` (`envelope.ts`). The Worker alone adds a locked-down tracker's ingest header (`ingest.ts`, `ERROR_REPORTING_INGEST_KEY`), to its own events and to forwards for that tracker. How it is wired into the apps and the tracker: [error reporting](/docs/architecture/observability#error-reporting).

## Public exports [#public-exports]

| Subpath             | Target                     |
| ------------------- | -------------------------- |
| `./scrub`           | `./src/scrub.ts`           |
| `./early`           | `./src/early.ts`           |
| `./browser`         | `./src/browser.ts`         |
| `./browser-sdk`     | `./src/browser-sentry.ts`  |
| `./worker`          | `./src/worker.ts`          |
| `./envelope-ingest` | `./src/envelope-ingest.ts` |
| `./tunnel-path`     | `./src/tunnel-path.ts`     |
| `./native`          | `./src/native.ts`          |

These paths come from `packages/error-reporting/package.json`. `scrub`, `early` and `tunnel-path` are LEAF modules (no imports). `browser-sdk` is the lazily imported SDK chunk: import it only with `import()` after hydration. `worker` and `envelope-ingest` are server-only (client boundary lint). The ingest module owns the settings, wire limit, sender allowance and forward for both routes. Ingest headers, relay preparation and the envelope reader are internal modules. `native` imports the app's own `@sentry/react-native`; it turns the native SDKs on when the DSN names the server (the relay) and takes a tunnel URL, with the native SDKs off, when it names the tracker.

## How to extend [#how-to-extend]

Add a project's private keys (health data first) to `PROJECT_SENSITIVE_KEYS` in `scrub.ts`; they are removed at any depth of every event, breadcrumb, tag and context. Turn on another kind of data (tracing, sessions, replays) only in this package, with a test that the envelope still carries no personal data, and measure the bundle again.

## Key files [#key-files]

- [`packages/error-reporting/src/scrub.ts`](https://github.com/CarlosZiegler/fofo/blob/main/packages/error-reporting/src/scrub.ts)
- [`packages/error-reporting/src/options.ts`](https://github.com/CarlosZiegler/fofo/blob/main/packages/error-reporting/src/options.ts)
- [`packages/error-reporting/src/worker.ts`](https://github.com/CarlosZiegler/fofo/blob/main/packages/error-reporting/src/worker.ts)
- [`packages/error-reporting/src/envelope-ingest.ts`](https://github.com/CarlosZiegler/fofo/blob/main/packages/error-reporting/src/envelope-ingest.ts)
- [`packages/error-reporting/src/relay.ts`](https://github.com/CarlosZiegler/fofo/blob/main/packages/error-reporting/src/relay.ts)
- [`scripts/check-error-reporting-imports.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/check-error-reporting-imports.mjs)
