Documentation
Monitoring (Sentry)
Sentry error monitoring — setup, performance traces, source maps, and production debugging.
Motoko Base uses Sentry for error monitoring in production. There is no monitoring dashboard in the app — use the Sentry web UI.
Official docs: Sentry Next.js documentation
Setup
- Create a Sentry project (platform: Next.js)
- Copy the DSN from Project Settings → Client Keys
- For source maps (production builds), create an auth token with release upload permission
- Set env vars:
| Variable | Scope | Purpose |
|---|---|---|
NEXT_PUBLIC_SENTRY_DSN | Public | Enables Sentry when set |
SENTRY_AUTH_TOKEN | CI / build | Source map upload |
SENTRY_ORG | CI / build | Organization slug |
SENTRY_PROJECT | CI / build | Project slug |
Leave DSN unset to disable monitoring entirely.
Development vs production
Sentry is off during next dev (even with DSN set) to avoid webpack listener noise. To test locally:
pnpm build && pnpm startPerformance sampling: 10% in production, 0% otherwise. Session Replay and User Feedback are off by default.
Errors & performance
- Unhandled exceptions are captured automatically (client + server)
- App Router errors:
src/app/global-error.tsx,src/app/dashboard/error.tsx - Manual capture for caught failures:
import { captureException } from "@/lib/monitoring";
try {
// ...
} catch (error) {
captureException(error); // fail-open — never throws
}Do not report expected outcomes (validation errors, signed-out, not-found, missing config).
Authenticated user id is attached on sign-in (Sentry.setUser({ id })), cleared on sign-out.
Source maps
next.config.ts wraps the build with withSentryConfig. When SENTRY_AUTH_TOKEN, SENTRY_ORG, and SENTRY_PROJECT are set in CI:
- Source maps upload during
next build - Client maps deleted after upload
- Stack traces resolve to TypeScript in Sentry Issues
Builds succeed without upload credentials — you just won't get readable stacks.
Browser events can tunnel through /sentry-tunnel (helps with ad blockers).
Production debugging
- Open Sentry → Issues
- Filter by
environment: production - Click an issue → stack trace, breadcrumbs, user id
- Reproduce with
pnpm build && pnpm startlocally against a non-production Sentry project
Sensitive data is scrubbed (src/lib/monitoring/scrub.ts) — no passwords, tokens, API keys, or AI prompts.
Where to change this
| What | Where |
|---|---|
| Enable rules & sampling | src/lib/monitoring/config.ts |
| Scrubbing | src/lib/monitoring/scrub.ts |
| Shared init options | src/lib/monitoring/options.ts |
captureException, user context | src/lib/monitoring/index.ts |
| Client init | src/instrumentation-client.ts |
| Server/edge init | src/instrumentation.ts, sentry.server.config.ts, sentry.edge.config.ts |
| Build / source maps | next.config.ts |
Environment Variables — all Sentry env vars.