Building Type-Safe APIs with Nuxt 3 and Prisma
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Set up proper monitoring with structured logging, error tracking, performance metrics, and alerting before your users find the bugs.
Mbeah Essilfie
May 22, 2026 at 06:04 AM
Monitoring tells you something is wrong (alert: 500 errors spiking). Observability helps you understand why (trace the request through your system).
The three pillars: Logs, Metrics, Traces.
// ❌ Unstructured — hard to search and parse
console.log('User ' + userId + ' created post ' + postId)
// ✅ Structured — queryable and parseable
logger.info('Post created', {
userId,
postId,
duration: elapsed,
tags: post.tags,
})
A simple structured logger:
type LogLevel = 'debug' | 'info' | 'warn' | 'error'
function createLogger(service: string) {
return {
info: (message: string, meta?: Record<string, unknown>) =>
emit('info', message, meta),
error: (message: string, error?: Error, meta?: Record<string, unknown>) =>
emit('error', message, { ...meta, error: error?.stack }),
}
function emit(level: LogLevel, message: string, meta?: Record<string, unknown>) {
const entry = {
timestamp: new Date().toISOString(),
level,
service,
message,
...meta,
}
console.log(JSON.stringify(entry))
}
}
const logger = createLogger('api')
// server/plugins/error-tracking.ts
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('error', (error, { event }) => {
// Send to Sentry, Bugsnag, etc.
reportError({
error,
url: event?.path,
user: event?.context?.user?.id,
timestamp: Date.now(),
})
})
})
Application metrics:
Infrastructure metrics:
// server/api/health.get.ts
export default defineEventHandler(async () => {
const checks = {
database: await checkDb(),
redis: await checkRedis(),
storage: await checkS3(),
}
const healthy = Object.values(checks).every(c => c.status === 'ok')
return {
status: healthy ? 'healthy' : 'degraded',
checks,
version: process.env.APP_VERSION,
uptime: process.uptime(),
}
})
Set alerts based on:
Key principle: Alert on symptoms (users are affected), not causes (CPU is high). High CPU that doesn't impact users isn't an emergency.
You don't need a full observability platform on day one:
Add complexity only when you need to answer questions your current tools can't.
Fullstack Software Developer
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Go beyond basic utility classes and learn how to build cohesive, maintainable design systems with Tailwind CSS.
Understand the power of Vue 3's Composition API through practical, real-world composable patterns that you can use today.
