Monitoring

Monitor and observe your ShipKit application

Monitoring Your ShipKit Application

Effective monitoring is crucial for maintaining a healthy production environment. Here's how to set up comprehensive monitoring for your ShipKit application.

Monitoring Stack

Vercel Analytics

Built-in performance monitoring and analytics

Sentry

Error tracking and performance monitoring

Performance Monitoring

Web Vitals

ShipKit automatically tracks Web Vitals metrics:

export function Analytics() {
  return <WebVitals />
}

Custom Metrics

Track custom metrics for business-critical operations:

export async function trackMetric(name: string, value: number) {
  if (process.env.NODE_ENV === 'production') {
    // Send to your analytics platform
    await analytics.track({
      name,
      value,
      timestamp: Date.now(),
    })
  }
}

Error Tracking

Set up Sentry for comprehensive error tracking:

import * as Sentry from '@sentry/nextjs'

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 1.0,
  debug: process.env.NODE_ENV === 'development',
})

Logging

Use structured logging for better observability:

import { logger } from '@/lib/logger'

logger.info('User action', {
  userId: user.id,
  action: 'login',
  timestamp: new Date().toISOString(),
})

Health Checks

Implement health check endpoints:

// app/api/health/route.ts
import { NextResponse } from 'next/server'
import { db } from '@/lib/db'

export async function GET() {
  try {
    // Check database connection
    await db.raw('SELECT 1')
    
    return NextResponse.json({
      status: 'healthy',
      timestamp: new Date().toISOString(),
    })
  } catch (error) {
    return NextResponse.json({
      status: 'unhealthy',
      error: error.message,
    }, { status: 500 })
  }
}

Alerting

Set up alerts for critical issues:

  • Response time exceeds threshold
  • Error rate spikes
  • Memory usage high
  • CPU usage high
  • Disk space low
  • Database connection issues

Dashboards

Create monitoring dashboards for:

  • Application performance
  • Error rates
  • User activity
  • Business metrics
  • Infrastructure health
  • API performance

Best Practices

  • Monitor all critical paths
  • Set up proper alerting thresholds
  • Use structured logging
  • Implement proper error boundaries
  • Track business metrics
  • Monitor third-party services
  • Set up uptime monitoring
  • Use proper logging levels
  • Implement proper error handling
  • Regular monitoring review