Observability
Sentry error tracking across web, API and scraper — the cal.diy pattern
Gap severity: HIGH — still open
KwadMarket has no error tracking at all: every unhandled production error is silent. Tracked as plan phase 7 / Operations §6. This page keeps the full wiring recipe.
The cal.diy pattern
Full Sentry integration across three runtimes:
apps/web/sentry.server.config.ts — Node.js server
apps/web/sentry.edge.config.ts — Edge runtime
apps/web/instrumentation.ts — Next.js instrumentation hook (loads per runtime)
apps/web/instrumentation-client.ts — Browser-sideinstrumentation.ts uses Next.js's onRequestError hook to capture every unhandled server error:
export const onRequestError: Instrumentation.onRequestError = (err, request, context) => {
if (process.env.NODE_ENV === "production") {
Sentry.captureRequestError(err, request, context);
}
};sentry.server.config.ts tags events with errorSource: "server", uses Sentry.prismaIntegration() (captures slow queries), and exposes configurable sample rates via env vars (SENTRY_SAMPLE_RATE, SENTRY_TRACES_SAMPLE_RATE).
What to implement
- Install
@sentry/nextjs. - Create
apps/web/sentry.server.config.ts,apps/web/sentry.edge.config.ts,apps/web/instrumentation-client.ts. - Wire
apps/web/instrumentation.tswith theregister/onRequestErrorpattern. - Add
withSentryConfig()wrapper inapps/web/next.config.ts. - Source maps upload at build time; attach userId as user context.
- Install
@sentry/nestjs. - Add
SentryModule.forRootAsync()inapps/back/src/app.module.ts. - Add
SentryGlobalFilteras a global exception filter inapps/back/src/main.ts— capture non-HttpExceptionerrors and 5xx only. - Tag errors with userId, dealId, route, environment.
- Install
@sentry/node. - Capture scraping failures per source — failed scrape jobs should be visible somewhere other than Redis.
- Alert on scraper downtime (e.g. a shop changed its DOM structure).
Env vars to add to .env.example:
NEXT_PUBLIC_SENTRY_DSN=
SENTRY_SAMPLE_RATE=0.1
SENTRY_TRACES_SAMPLE_RATE=0.01
SENTRY_ORG=
SENTRY_PROJECT=Alerts & uptime
| Alert | Condition | Channel |
|---|---|---|
| Error spike | >10 errors in 5 min | Slack/Discord |
| New unhandled error | First occurrence | |
| Scraper failure | Scraper job fails 3× | |
| API down | Health check fails | SMS (Better Stack) |
Pair with a /api/health endpoint (terminus — see Operations §6) and an uptime monitor (Uptime Robot / Better Stack free tier).