How to Monitor Your tRPC API with Vigilmon
tRPC makes type-safe API calls feel like local function calls — but when your tRPC procedure goes down in production, you still need external uptime monitoring. This guide shows you how to monitor your tRPC API with Vigilmon.
Why Monitor tRPC Endpoints?
tRPC runs on top of HTTP, so all tRPC procedures are standard HTTP endpoints under the hood. When a tRPC procedure fails, users see a type error or a network error — not a helpful message. External uptime monitoring catches these failures before users report them.
Common tRPC monitoring scenarios:
- Your
/api/trpc/users.getUserprocedure is returning 500s - Your Next.js serverless function is cold-starting too slowly
- Your database connection inside a tRPC procedure is failing
- Your tRPC deployment on Vercel/Railway is down entirely
Understanding tRPC's HTTP Layer
tRPC procedures are called via HTTP GET (queries) or HTTP POST (mutations). The URL format is:
# Query (GET)
https://yourapp.com/api/trpc/router.procedure?input={"json":{}}
# Mutation (POST)
https://yourapp.com/api/trpc/router.procedure
For monitoring purposes, the easiest approach is to create a dedicated health check procedure that Vigilmon can poll.
Step 1: Create a tRPC Health Check Procedure
Add a health router to your tRPC setup:
// server/routers/health.ts
import { publicProcedure, router } from '../trpc';
export const healthRouter = router({
check: publicProcedure.query(async ({ ctx }) => {
// Optionally check DB connectivity
await ctx.db.$queryRaw`SELECT 1`;
return {
status: 'ok',
timestamp: new Date().toISOString(),
};
}),
});
Merge it into your main router:
// server/routers/_app.ts
import { router } from '../trpc';
import { healthRouter } from './health';
import { usersRouter } from './users';
export const appRouter = router({
health: healthRouter,
users: usersRouter,
// ... other routers
});
Step 2: Expose as a REST-Like Endpoint
For Vigilmon (and any HTTP monitor), the tRPC query URL looks like:
https://yourapp.com/api/trpc/health.check?input={"json":null}&batch=1
tRPC batching adds batch=1 by default. The response shape is:
[{"result":{"data":{"json":{"status":"ok","timestamp":"2026-08-04T..."}}}}}]
Step 3: Add a Vigilmon Monitor
- Log in to vigilmon.online
- Click Add Monitor
- Set URL to your health endpoint:
https://yourapp.com/api/trpc/health.check?input={"json":null}&batch=1
- Set Monitor Type to HTTP/HTTPS
- Set Check Interval to 60 seconds
- Under Advanced, set Expected Status Code to
200 - Optionally set Expected Response Body to contain
"status":"ok"(string match) - Click Save
Vigilmon will now check your tRPC health endpoint every minute from multiple global regions.
Step 4: Monitor Critical Procedures Separately
Beyond a generic health check, you can monitor individual critical procedures:
// server/routers/health.ts
export const healthRouter = router({
check: publicProcedure.query(async ({ ctx }) => {
return { status: 'ok', timestamp: new Date().toISOString() };
}),
// Check that auth service is reachable
authCheck: publicProcedure.query(async ({ ctx }) => {
const user = await ctx.db.user.findFirst({ where: { email: 'health@vigilmon.internal' } });
return { status: 'ok', dbConnected: true };
}),
});
Create a separate Vigilmon monitor for each critical path:
-
/api/trpc/health.check→ main app health -
/api/trpc/health.authCheck→ auth + database health
Handling tRPC on Next.js App Router
With Next.js App Router and @trpc/next, your tRPC handler is at app/api/trpc/[trpc]/route.ts. The URL structure is the same:
// app/api/trpc/[trpc]/route.ts
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { appRouter } from '@/server/routers/_app';
import { createContext } from '@/server/context';
const handler = (req: Request) =>
fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext,
});
export { handler as GET, handler as POST };
Vigilmon monitors this identically — the URL is the same.
Setting Up Alerts
In Vigilmon, configure alerts so you're notified immediately when your tRPC API goes down:
- Go to Alert Channels → Add Channel
- Add your email, Slack webhook, or PagerDuty integration
- Set the alert threshold (e.g., alert after 1 failed check from 2+ regions)
Multi-Region Coverage
Vigilmon's multi-region consensus model means your tRPC monitor won't false-alert if one probe node has a bad network path. An alert only fires when multiple globally distributed nodes confirm your endpoint is unreachable — critical if your app is deployed on Vercel Edge or Cloudflare Workers where regional variance matters.
What to Monitor
For a production tRPC app, set up monitors for:
| Endpoint | Purpose |
|---|---|
/api/trpc/health.check |
Basic app health |
/api/trpc/health.authCheck |
Database + auth layer |
| Your tRPC base URL | Catches Next.js routing failures |
| Your frontend domain | End-to-end availability |
Heartbeat Monitoring for tRPC Background Jobs
If you run background tasks triggered by tRPC mutations (e.g., via a cron that calls a tRPC procedure), use Vigilmon's heartbeat monitors to verify the jobs run on schedule:
// Your cron handler
export async function runDailyJob() {
// ... job logic ...
// Ping Vigilmon heartbeat at the end
await fetch('https://vigilmon.online/api/heartbeat/YOUR_HEARTBEAT_ID');
}
If the heartbeat ping doesn't arrive on schedule, Vigilmon alerts you.
Conclusion
tRPC's type safety doesn't protect you from server-side failures that external users experience. Adding Vigilmon monitoring to your tRPC health endpoint takes 2 minutes and gives you multi-region uptime tracking, SSL certificate monitoring, and instant alerts when your API goes down.
Top comments (0)