Monitoring Overview

Current monitoring behavior in the Next.js Drizzle SaaS Kit.

The monitoring layer in this repo is extensible, but the checked-in runtime currently supports one built-in provider: Sentry.

Current State

  • @kit/monitoring-core provides the base service types and console fallback
  • @kit/monitoring provides provider selection, hooks, and server helpers
  • @kit/sentry is the only registered concrete provider in the repo
  • If NEXT_PUBLIC_MONITORING_PROVIDER is unset, the app falls back to console logging

Supported Provider Values

Current runtime support:

  • sentry
  • empty / unset value for console fallback

Other provider names are not registered by default in this repository.

Quick Start

apps/web/.env.local

NEXT_PUBLIC_MONITORING_PROVIDER=sentry
NEXT_PUBLIC_SENTRY_DSN=https://xxxxx@xxxxx.ingest.sentry.io/xxxxx

Manual Capture

Client-side:

import { useMonitoring } from '@kit/monitoring/hooks';
function MyComponent() {
const monitoring = useMonitoring();
async function onSubmit() {
try {
await submitForm();
} catch (error) {
monitoring.captureException(error as Error, {
context: 'form_submission',
});
}
}
}

Server-side:

import { getServerMonitoringService } from '@kit/monitoring/server';
export async function processPayment() {
const monitoring = await getServerMonitoringService();
try {
// ...
} catch (error) {
await monitoring.captureException(error as Error);
throw error;
}
}

Extending Monitoring

You can add more providers, but they are not prewired in this repo. To do that:

  1. implement a monitoring service
  2. add the provider name to packages/monitoring/api/src/get-monitoring-provider.ts
  3. register the provider in the client and server registries

See Custom Monitoring Provider for the pattern.

Topics

  1. Sentry
  2. Custom Monitoring Provider
  3. Capturing Errors