KwadMarket Docs
Best Practices

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-side

instrumentation.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

  1. Install @sentry/nextjs.
  2. Create apps/web/sentry.server.config.ts, apps/web/sentry.edge.config.ts, apps/web/instrumentation-client.ts.
  3. Wire apps/web/instrumentation.ts with the register / onRequestError pattern.
  4. Add withSentryConfig() wrapper in apps/web/next.config.ts.
  5. Source maps upload at build time; attach userId as user context.
  1. Install @sentry/nestjs.
  2. Add SentryModule.forRootAsync() in apps/back/src/app.module.ts.
  3. Add SentryGlobalFilter as a global exception filter in apps/back/src/main.ts — capture non-HttpException errors and 5xx only.
  4. Tag errors with userId, dealId, route, environment.
  1. Install @sentry/node.
  2. Capture scraping failures per source — failed scrape jobs should be visible somewhere other than Redis.
  3. 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

AlertConditionChannel
Error spike>10 errors in 5 minSlack/Discord
New unhandled errorFirst occurrenceEmail
Scraper failureScraper job fails 3×Email
API downHealth check failsSMS (Better Stack)

Pair with a /api/health endpoint (terminus — see Operations §6) and an uptime monitor (Uptime Robot / Better Stack free tier).

On this page