# Creating a Custom Monitoring Provider

> Extend the monitoring abstraction with your own provider.

*Canonical: https://makerkit.dev/docs/nextjs-prisma/monitoring/custom-provider*

---

If you need a provider other than Sentry, add it through the monitoring abstraction.

## Steps

1. Implement `MonitoringService`
2. Register the provider in `packages/monitoring/api/src/get-monitoring-provider.ts`
3. Register the client provider in `packages/monitoring/api/src/components/provider.tsx`
4. Register the server service in `packages/monitoring/api/src/services/get-server-monitoring-service.ts`
5. Register a server instrumentation entry in `packages/monitoring/api/src/instrumentation.ts` — must export both `register()` and `onRequestError`. `onRequestError` is required so client `error.tsx` can safely dedup server-origin errors via `error.digest`.
6. Register a client instrumentation entry in `packages/monitoring/api/src/instrumentation-client.ts` — must export `init()` and a `captureException(error, mechanism)` used by the package-owned `window.onerror` / `unhandledrejection` / boundary handlers.

## Core Types

Use these files as the source of truth:

- `packages/monitoring/core/src/monitoring.service.ts`
- `packages/monitoring/core/src/monitoring.context.ts`
- `packages/monitoring/api/src/get-monitoring-provider.ts`
- `packages/monitoring/api/src/instrumentation.ts`
- `packages/monitoring/api/src/instrumentation-client.ts`

## Important Constraint

The provider name must be added to the `MONITORING_PROVIDERS` enum. Without that change, `NEXT_PUBLIC_MONITORING_PROVIDER` will be treated as invalid and the app will fall back to the console service.
