Skip to content

feat: add Sentry error tracking wiring with env var gate - #521

Open
ZacLou wants to merge 1 commit into
conduit-protocol:mainfrom
ZacLou:feat/sentry-error-tracking-478
Open

ZacLou wants to merge 1 commit into
conduit-protocol:mainfrom
ZacLou:feat/sentry-error-tracking-478

Conversation

@ZacLou

@ZacLou ZacLou commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses #478

Changes

lib/error-tracking.ts (new)

A lightweight error tracking wrapper with four functions:

  • captureError(error, context?) — captures an error with optional tags and extra data. When Sentry DSN is unset, logs to console. When set, would call Sentry.captureException() (structured for one-line upgrade).
  • addBreadcrumb(crumb) — adds breadcrumbs (max 20) attached to the next captured error
  • withErrorTracking(fn, context?) — wraps an async function so errors are automatically captured
  • initErrorTracking() — installs unhandledrejection and error listeners on window

All functions are no-ops when NEXT_PUBLIC_SENTRY_DSN is unset — the app runs identically with or without Sentry configured.

Wiring

  • app/layout.tsx — calls initErrorTracking() on mount
  • components/ErrorBoundary.tsxcomponentDidCatch calls captureError() with component stack
  • app/streams/page.tsx — RPC errors captured with source: 'streams-page' tag
  • app/dashboard/page.tsx — RPC errors captured with source: 'dashboard-page' tag
  • .env.example — documents NEXT_PUBLIC_SENTRY_DSN

Upgrade path

When @sentry/nextjs is installed, only captureError() needs to change:

// Replace the console.error line with:
Sentry.withScope(scope => {
  if (context?.tags) Object.entries(context.tags).forEach(([k, v]) => scope.setTag(k, v))
  if (context?.extra) Object.entries(context.extra).forEach(([k, v]) => scope.setExtra(k, v))
  breadcrumbs.forEach(c => scope.addBreadcrumb(c))
  Sentry.captureException(err)
})

No other code changes needed.

@ZacLou
ZacLou force-pushed the feat/sentry-error-tracking-478 branch from 30f6807 to 5c4f34b Compare September 5, 2026 15:56
…tocol#478)

Adds a lightweight error tracking layer that captures unhandled errors,
ErrorBoundary catches, and failed RPC calls with breadcrumbs. Gated on
NEXT_PUBLIC_SENTRY_DSN — when unset, all functions are no-ops.

- lib/error-tracking.ts: captureError, addBreadcrumb, withErrorTracking,
  initErrorTracking (no-ops when DSN is unset)
- app/layout.tsx: calls initErrorTracking() on mount
- components/ErrorBoundary.tsx: captures errors with component stack
- app/streams/page.tsx, app/dashboard/page.tsx: captures RPC errors
- .env.example: documents NEXT_PUBLIC_SENTRY_DSN

The API is structured so adding @sentry/nextjs is a one-line change
in captureError() — just replace the console.error with Sentry calls.

Addresses conduit-protocol#478
@ZacLou
ZacLou force-pushed the feat/sentry-error-tracking-478 branch from 5c4f34b to c386530 Compare September 5, 2026 15:58
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