Skip to content

feat(core): browser capture MVP — global handlers, breadcrumbs, transport, stack parser - #1

Merged
brentrager merged 1 commit into
mainfrom
sdk-capture-handlers-v0.2
May 17, 2026
Merged

feat(core): browser capture MVP — global handlers, breadcrumbs, transport, stack parser#1
brentrager merged 1 commit into
mainfrom
sdk-capture-handlers-v0.2

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Summary

Makes the SDK actually capture and ship events. Up until this commit, `Client.init` was a no-op for capture. Now it:

  • Registers `window.onerror` + `unhandledrejection` global handlers (compose-safe).
  • Installs `fetch` + navigation breadcrumb wrappers (PII-scrubbed urls).
  • Stands up a batched transport: `maxBatchSize=30`, `flushIntervalMs=1000`, POST `{ type: 'error', events: [...] }` with `keepalive: true`, `navigator.sendBeacon` fallback on `pagehide`/`visibilitychange:hidden`, oldest-event-drop queue cap.
  • Parses real V8 / Spidermonkey / JSCore stacks (the prior placeholder returned `{module: 'unparsed'}`).
  • Walks `Error.cause` into nested `ExceptionInfo`.
  • Strips SDK-internal frames so user stacks don't start with our own code.
  • Scrubs PII before transport: Bearer tokens, `password=`, `token/api_key=`, OpenAI `sk-...` keys, sensitive headers (`authorization`, `cookie`, `x-api-key`, `x-auth-token`).

Optional console.error tap is wired but off by default — turn it on with autoInstrumentation flag.

What this unblocks

This is the piece that makes SmooAI/smooai dogfooding on smoo.ai possible. Backend ingest + dashboard pages live in SmooAI/smooai; this is the SDK side that ships the events.

Test plan

  • `pnpm typecheck` (all 5 turbo tasks green)
  • `pnpm test` — 3 new test files, 13 assertions total, all pass
    • stack-parser: V8 stack, Firefox/Safari stack, node_modules detection, Error-header skip
    • transport: max-batch immediate flush, timer flush, queue overflow, beacon
    • pii: Bearer redaction, password redaction, sk- redaction, sensitive headers
  • `pnpm build` (ESM + .d.ts for all three packages)
  • `pnpm format` (Prettier applied)

Versioning

Changeset: minor bump → `@smooai/observability@0.2.0`. React and Next wrappers unchanged (still 0.1.0).

Follow-ups

Tracked in SmooAI/smooai SMOODEV-1067 as separate pearls:

  • Node-side capture handlers + Hono middleware
  • XHR wrapper (we cover `fetch` only here)
  • IndexedDB offline queue (currently events just back-of-line on transport failure)
  • Build-time sourcemap upload (`@smooai/observability-next/build`)
  • Click + form-submit breadcrumb wrappers

🤖 Generated with Claude Code

What works now:

- window.onerror + window.onunhandledrejection auto-registered on Client.init,
  composing with any prior handlers so we don't clobber app code.
- fetch wrapper produces breadcrumbs (method, url, status, duration) with the
  url scrubbed for PII; XHR wrapper deferred.
- navigation breadcrumbs for pushState, replaceState, popstate, hashchange.
- Optional console.error tap (off by default).
- Batched transport: maxBatchSize=30, flushIntervalMs=1000, queue cap with
  oldest-event drop on overflow. POST { type: 'error', events: [...] } to dsn
  with keepalive:true.
- navigator.sendBeacon fallback on pagehide + visibilitychange:hidden so
  events survive bfcache transitions.
- PII scrub: Bearer tokens, password=, token/api_key=, sk-... OpenAI keys,
  sensitive headers (authorization, cookie, x-api-key, x-auth-token).
- Engine-agnostic stack parser (V8 + Spidermonkey/Safari).
- Error.cause chains captured as nested ExceptionInfo.
- SDK-internal frames stripped from captured stacks.
- Tests: stack-parser (5), transport (4), pii (4) — all pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented May 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c0022cd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@smooai/observability Minor
@smooai/observability-next Minor
@smooai/observability-react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager
brentrager merged commit 40bbb38 into main May 17, 2026
1 check failed
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