How to Monitor tRPC APIs with Vigilmon (Uptime + Health Checks)
tRPC has become the go-to choice for end-to-end type-safe APIs in TypeScript projects - especially in the T3 stack with Next.js. But tRPC's router-based architecture introduces monitoring challenges that traditional REST uptime tools weren't designed for.
This guide covers how to set up external uptime monitoring for your tRPC API so you know when your backend is down - before your users do.
Why tRPC APIs Need External Monitoring
tRPC endpoints don't follow REST conventions. There are no GET /api/health routes by default. If your tRPC router crashes or the underlying server goes down, users see cryptic TypeScript errors and your dashboard shows nothing.
External uptime monitoring catches:
- Server process crashes (Node/Bun process dies)
- Database connection failures (your resolvers start returning 500s)
- Memory leaks causing response timeouts
- Deployment failures that break the API layer
- Edge function cold start degradation
Setting Up a tRPC Health Check Endpoint
The easiest approach is a dedicated health procedure in your router that Vigilmon can ping:
` ypescript
// server/trpc/router/health.ts
import { publicProcedure, router } from '../trpc';
import { db } from '../../db';
export const healthRouter = router({
ping: publicProcedure.query(async () => {
// Check DB connectivity
await db.\SELECT 1\;
return { status: 'ok', timestamp: new Date().toISOString() };
}),
});
`
Merge it into your root router:
` ypescript
// server/trpc/root.ts
import { healthRouter } from './router/health';
export const appRouter = router({
health: healthRouter,
// ...your other routers
});
`
The health ping is now accessible at your tRPC endpoint URL as a GET or POST depending on your adapter.
Configure Your tRPC Adapter for GET Requests
Vigilmon uses HTTP GET requests by default. If you're using @trpc/server with an HTTP adapter, enable GET queries:
` ypescript
// Next.js pages/api/trpc/[trpc].ts
import { createNextApiHandler } from '@trpc/server/adapters/next';
import { appRouter } from '../../../server/trpc/root';
export default createNextApiHandler({
router: appRouter,
createContext: () => ({}),
allowMethodOverride: true, // allows GET for queries
});
`
Your health endpoint URL becomes:
https://yourapp.com/api/trpc/health.ping
Setting Up Vigilmon
- Sign up at vigilmon.online
- Add a new HTTP monitor
- URL: https://yourapp.com/api/trpc/health.ping
- Method: GET
- Keyword check: Add "status":"ok" to verify the response contains a valid JSON payload - not just a 200 status
- Check interval: 1 minute for production
- Alert channels: Add your email or webhook
The keyword check is important for tRPC. A failed database query might still return HTTP 200 with a tRPC error body. Checking for "status":"ok" in the response body means Vigilmon only marks the monitor as up when your health check fully passes.
Advanced: Monitoring Multiple Procedures
If you have critical procedures you want to monitor independently (payment processing, auth, data sync), you can create procedure-specific health checks:
` ypescript
export const healthRouter = router({
ping: publicProcedure.query(() => ({ status: 'ok' })),
database: publicProcedure.query(async () => {
await db.\SELECT 1\;
return { status: 'ok', service: 'database' };
}),
cache: publicProcedure.query(async () => {
await redis.ping();
return { status: 'ok', service: 'cache' };
}),
});
`
Then set up separate Vigilmon monitors for each critical dependency:
- /api/trpc/health.ping - server process
- /api/trpc/health.database - database connectivity
- /api/trpc/health.cache - cache layer
Heartbeat Monitoring for tRPC Background Jobs
If you have tRPC procedures that run scheduled jobs or queues, use Vigilmon's heartbeat monitoring to ensure they run on schedule:
` ypescript
// In your cron job or queue worker
import { appRouter } from '../trpc/root';
const caller = appRouter.createCaller({});
async function processQueue() {
// ...your job logic
// Signal Vigilmon the job completed
await fetch('https://vigilmon.online/hb/your-heartbeat-id', {
method: 'POST',
});
}
`
Vigilmon alerts you if the heartbeat hasn't been received within the expected window - catching stuck queues before users notice.
What to Monitor
A solid tRPC monitoring setup includes:
- Uptime monitor on the health endpoint (1-minute checks)
- Keyword verification to confirm the health check passes, not just responds
- Multi-region checks - Vigilmon checks from multiple locations to avoid ISP-level false positives
- SSL certificate monitoring on the base domain
- Heartbeat monitors for scheduled background jobs
Common tRPC Monitoring Pitfalls
TRPC errors return 200: Vigilmon's status code check alone isn't enough. Always use keyword matching to verify the response body.
Authentication middleware blocks health checks: Your health router's procedures should use publicProcedure, not protectedProcedure, so Vigilmon can reach them without auth tokens.
WebSocket subscriptions: Vigilmon monitors HTTP endpoints. For tRPC subscriptions over WebSockets, monitor the underlying HTTP server's health endpoint separately.
Summary
tRPC's type safety is a developer experience win, but it requires a bit of extra setup to make traditional uptime monitoring work. A dedicated health router with Vigilmon monitoring gives you the visibility to catch backend failures before users report them.
Sign up for a free Vigilmon account and add your first tRPC health endpoint in under 5 minutes.
Top comments (0)