How to Monitor Your tRPC API with Vigilmon
tRPC is one of the most developer-friendly ways to build type-safe APIs for TypeScript full-stack apps — no code generation, no schema files, just end-to-end type safety between your Next.js frontend and Node.js backend.
tRPC is one of the most developer-friendly ways to build type-safe APIs for TypeScript full-stack apps — no code generation, no schema files, just end-to-end type safety between your Next.js frontend and Node.js backend. But once your tRPC API is in production, you need to monitor it like any other service.
This guide covers how to add external uptime monitoring to your tRPC API with Vigilmon.
What Can Go Wrong with tRPC in Production?
tRPC runs as HTTP endpoints (typically under /api/trpc) in your Next.js app or standalone Node.js server. Failure modes include:
- Server crashes: Unhandled exceptions in procedures
- Database connectivity issues: Your tRPC procedures can't reach their data sources
- Cold start latency: Serverless deployments (Vercel, AWS Lambda) may be slow after idle periods
- Deployment failures: A bad deploy breaks the build or causes runtime errors
- Middleware errors: Auth middleware throwing unexpected errors
External monitoring catches all of these from the outside, the same way your users experience them.
Step 1: Add a Health Check Procedure (or Endpoint)
tRPC doesn't ship a built-in health check, but adding one is straightforward.
Option A: Add a tRPC query procedure
// server/routers/health.ts
import { publicProcedure, router } from '../trpc';
export const healthRouter = router({
check: publicProcedure.query(async ({ ctx }) => {
// Optionally verify DB connection
await ctx.db.$queryRaw`SELECT 1`;
return { status: 'healthy', timestamp: new Date().toISOString() };
}),
});
Then call it via: GET /api/trpc/health.check?input={}
Option B: Add a plain HTTP health endpoint alongside tRPC (recommended)
// pages/api/health.ts (Next.js)
import type { NextApiRequest, NextApiResponse } from 'next';
import { db } from '../../lib/db';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
await db.$queryRaw`SELECT 1`;
res.status(200).json({ status: 'healthy' });
} catch (error) {
res.status(503).json({ status: 'unhealthy' });
}
}
Option B is simpler to monitor since it returns a clean 200/503 without needing to parse tRPC's response envelope.
Step 2: Sign Up for Vigilmon
Go to vigilmon.online — the free tier gives you 10 monitors with 3-minute check intervals. No credit card required.
Step 3: Add an HTTP Monitor
In the Vigilmon dashboard:
- Click Add Monitor
- Select HTTP monitor type
- Enter your health URL:
https://yourapp.com/api/health - Set expected status code: 200
- Enable multi-region checks (Vigilmon checks from US, EU, and AP simultaneously)
- Set check interval (3 min on free tier; 1 min available on paid plans from $6/month)
Step 4: Also Monitor Your tRPC Endpoint Directly
Add a second monitor targeting your main tRPC route:
- URL:
https://yourapp.com/api/trpc/health.check?input={} - Method: GET
- Expected status: 200
This catches cases where your health endpoint is fine but the tRPC router itself has crashed.
Step 5: Configure Alerts
Set up your preferred channels in Alert Settings:
| Channel | Best For |
|---|---|
| Immediate personal notification | |
| Slack | Team awareness in #alerts channel |
| Discord | Dev team on Discord servers |
| PagerDuty | On-call rotation and escalation |
| Webhooks | Automated responses (restart service, notify stakeholders) |
Key Metrics to Monitor
Response time trends: tRPC over serverless can have high cold-start latency. Vigilmon shows you response time over time — a sudden spike in p95 latency often precedes a full outage.
Regional availability: Vigilmon's multi-region checks (US, EU, AP) tell you if an issue is localized to one geography or truly global.
Uptime percentage: Track your actual uptime against your SLA. Even informal SLAs benefit from real data.
Alert Configuration Tips
Confirm from multiple regions before alerting: Avoid waking someone up at 3am for a 30-second transient network issue. Vigilmon lets you require confirmation from 2+ regions before firing an alert.
Create separate monitors per environment: Add Vigilmon monitors for both your staging and production deployments. You'll often catch breaking changes in staging before they reach prod.
Response time alerting: Set a threshold alert (e.g., if response time exceeds 5 seconds, alert). This is especially important for serverless tRPC deployments where cold starts can be a UX problem.
Heartbeat Monitors for tRPC Background Workers
If you use tRPC in combination with background job runners (like BullMQ, Inngest, or Trigger.dev), use Vigilmon's heartbeat monitor to verify jobs complete successfully. The job pings a unique Vigilmon URL on success; if the ping doesn't arrive within the expected interval, you get alerted.
The Full Stack Is Only as Reliable as Its Weakest Point
tRPC gives you incredible type safety, but it can't protect you from runtime failures. Pair it with Vigilmon to get real-time visibility into whether your API is actually serving users.
Set up your first monitor at vigilmon.online — it takes less than 5 minutes and it's completely free to start.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.