Documentation

Monitoring (Sentry)

Sentry error monitoring — setup, performance traces, source maps, and production debugging.

Open inChatGPT (opens in a new tab)Claude (opens in a new tab)Cursor (opens in a new tab)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

  1. Create a Sentry project (platform: Next.js)
  2. Copy the DSN from Project Settings → Client Keys
  3. For source maps (production builds), create an auth token with release upload permission
  4. Set env vars:
VariableScopePurpose
NEXT_PUBLIC_SENTRY_DSNPublicEnables Sentry when set
SENTRY_AUTH_TOKENCI / buildSource map upload
SENTRY_ORGCI / buildOrganization slug
SENTRY_PROJECTCI / buildProject 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 start

Performance 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

  1. Open Sentry → Issues
  2. Filter by environment: production
  3. Click an issue → stack trace, breadcrumbs, user id
  4. Reproduce with pnpm build && pnpm start locally 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

WhatWhere
Enable rules & samplingsrc/lib/monitoring/config.ts
Scrubbingsrc/lib/monitoring/scrub.ts
Shared init optionssrc/lib/monitoring/options.ts
captureException, user contextsrc/lib/monitoring/index.ts
Client initsrc/instrumentation-client.ts
Server/edge initsrc/instrumentation.ts, sentry.server.config.ts, sentry.edge.config.ts
Build / source mapsnext.config.ts

Environment Variables — all Sentry env vars.