Comprehensive guide for integrating real data sources, email notifications, and database persistence with the monitoring system.
- Database Setup
- Sentry Integration
- GitHub Integration
- Email Service Integration
- Feature Flags
- Testing
- PostgreSQL 14+ installed locally or access to a hosted instance
- Database created for the project
npm install @prisma/client
npm install -D prismaAdd to .env.local:
DATABASE_URL="postgresql://username:password@localhost:5432/claude_code_ui"# Generate Prisma Client
npx prisma generate
# Create database schema
npx prisma db push
# Or use migrations (recommended for production)
npx prisma migrate dev --name init# Open Prisma Studio to view/edit data
npx prisma studioThe schema includes:
- Escalation: Error escalations with priority and status tracking
- EscalationEvent: Timeline events for escalations
- Report: Generated reports storage
- ScheduledReport: Scheduled report configurations
- MergeConflict: Merge conflict resolution tracking
- HealthSnapshot: System health snapshots over time
- PipelineRun: CI/CD pipeline run history
- Sentry account with a project
- Auth token with appropriate permissions
- Go to https://sentry.io/settings/account/api/auth-tokens/
- Click "Create New Token"
- Select scopes:
project:readevent:readorg:read
- Copy the token
# Organization slug: found in URL
# https://sentry.io/organizations/YOUR_ORG_SLUG/
# Project slug: found in project settingsAdd to .env.local:
SENTRY_AUTH_TOKEN="your-auth-token-here"
SENTRY_ORG_SLUG="your-organization-slug"
SENTRY_PROJECT_SLUG="your-project-slug"ENABLE_REAL_DATA="true"The Sentry client provides:
import { createSentryClient } from '@/lib/integrations/sentry-client';
const client = createSentryClient();
if (client) {
// Get recent issues
const issues = await client.getIssues({ statsPeriod: '24h' });
// Get error trends
const trends = await client.getErrorTrends(7);
// Get top errors
const topErrors = await client.getTopErrors(10);
}- GitHub account with repository access
- Personal access token
- Go to https://github.com/settings/tokens
- Click "Generate new token" (classic)
- Select scopes:
repo(full control)workflow(for Actions data)
- Copy the token
# Owner: your username or organization name
# Repo: repository name (not full URL)Add to .env.local:
GITHUB_TOKEN="ghp_your-token-here"
GITHUB_OWNER="your-username-or-org"
GITHUB_REPO="your-repo-name"ENABLE_REAL_DATA="true"The GitHub client provides:
import { createGitHubClient } from '@/lib/integrations/github-client';
const client = createGitHubClient();
if (client) {
// Get CI/CD health
const health = await client.getCICDHealth(24);
// Get job performance
const jobPerf = await client.getJobPerformance(50);
// Get merge conflicts
const conflicts = await client.getMergeConflicts(7);
}Recommended for: Production deployments
- Create account at https://sendgrid.com
- Generate API key with "Mail Send" permissions
- Verify sender email address
EMAIL_PROVIDER="sendgrid"
EMAIL_FROM="monitoring@yourcompany.com"
SENDGRID_API_KEY="SG.your-api-key"Recommended for: Modern apps, best developer experience
- Create account at https://resend.com
- Add and verify your domain
- Generate API key
EMAIL_PROVIDER="resend"
EMAIL_FROM="monitoring@yourcompany.com"
RESEND_API_KEY="re_your-api-key"Recommended for: AWS infrastructure
- Set up AWS SES in your region
- Verify email addresses or domain
- Move out of sandbox mode
- Configure AWS credentials
EMAIL_PROVIDER="ses"
EMAIL_FROM="monitoring@yourcompany.com"
AWS_REGION="us-east-1"
AWS_ACCESS_KEY_ID="your-access-key"
AWS_SECRET_ACCESS_KEY="your-secret-key"Recommended for: On-premise or custom mail servers
EMAIL_PROVIDER="smtp"
EMAIL_FROM="monitoring@yourcompany.com"
SMTP_HOST="smtp.gmail.com"
SMTP_PORT="587"
SMTP_SECURE="false"
SMTP_USER="your-email@gmail.com"
SMTP_PASS="your-app-password"For Gmail:
- Enable 2-factor authentication
- Generate app-specific password
- Use that password in SMTP_PASS
ENABLE_EMAIL_NOTIFICATIONS="true"import { createEmailService } from '@/lib/email/email-service';
const emailService = createEmailService();
if (emailService) {
// Send report
await emailService.sendReport({
recipients: ['admin@company.com'],
reportName: 'Daily Monitoring Report',
reportContent: htmlContent,
reportFormat: 'html',
frequency: 'daily',
});
// Send alert
await emailService.sendAlert({
recipients: ['ops@company.com'],
title: 'Critical Error Detected',
message: 'High error rate detected in production',
priority: 'critical',
metadata: { errorCount: 150, affectedUsers: 50 },
});
}Control which integrations are active:
# Use real data from Sentry, GitHub APIs
ENABLE_REAL_DATA="false"
# Send actual email notifications
ENABLE_EMAIL_NOTIFICATIONS="false"
# Persist reports and metrics to database
ENABLE_DATABASE_PERSISTENCE="false"For local development, keep flags disabled:
ENABLE_REAL_DATA="false"
ENABLE_EMAIL_NOTIFICATIONS="false"
ENABLE_DATABASE_PERSISTENCE="false"This uses mock data and logs email notifications to console.
For staging environment, enable selectively:
ENABLE_REAL_DATA="true"
ENABLE_EMAIL_NOTIFICATIONS="false" # Don't spam real emails
ENABLE_DATABASE_PERSISTENCE="true"For production, enable all:
ENABLE_REAL_DATA="true"
ENABLE_EMAIL_NOTIFICATIONS="true"
ENABLE_DATABASE_PERSISTENCE="true"npx prisma db pullShould complete without errors.
# Create a test script
node -e "
const client = require('./lib/integrations/sentry-client').createSentryClient();
client.getIssues({ limit: 1 }).then(console.log).catch(console.error);
"Should return Sentry issues or empty array.
# Create a test script
node -e "
const client = require('./lib/integrations/github-client').createGitHubClient();
client.getWorkflowRuns({ per_page: 1 }).then(console.log).catch(console.error);
"Should return GitHub workflow runs.
# Create a test endpoint
# POST /api/test/email
# Body: { "to": "your-email@example.com" }Check your email inbox.
Error: Can't reach database server
- Check DATABASE_URL format
- Ensure PostgreSQL is running
- Verify network/firewall settings
Error: Invalid schema
- Run
npx prisma generate - Run
npx prisma db push
Error: Invalid token
- Generate new token at Sentry
- Check token has correct scopes
- Update SENTRY_AUTH_TOKEN
Error: Organization not found
- Verify SENTRY_ORG_SLUG matches URL
- Check token has access to organization
Error: Bad credentials
- Generate new personal access token
- Ensure token has
repoandworkflowscopes - Update GITHUB_TOKEN
Error: Resource not accessible
- Verify GITHUB_OWNER and GITHUB_REPO
- Check token has access to repository
SendGrid: Unauthorized
- Verify API key is correct
- Check API key hasn't been revoked
- Ensure sender email is verified
SES: Email address not verified
- Verify sender email in AWS SES
- Move out of SES sandbox mode for production
SMTP: Authentication failed
- For Gmail, use app-specific password
- Check SMTP credentials
- Verify SMTP settings (host, port, secure)
-
Never commit credentials
- Add
.env.localto.gitignore - Use environment variables in production
- Add
-
Rotate tokens regularly
- Set calendar reminders for token rotation
- Use short-lived tokens when possible
-
Minimum permissions
- Grant only necessary scopes
- Use read-only tokens where possible
-
Secure storage
- Use secret management services in production
- Examples: AWS Secrets Manager, HashiCorp Vault
-
Monitor API usage
- Track API call volumes
- Set up alerts for unusual activity
- Database migrations applied
- All environment variables configured
- Sentry integration tested
- GitHub integration tested
- Email service tested
- Feature flags set correctly
- Security review completed
- Monitoring dashboard accessible
- Reports generating successfully
- Alerts being sent as expected
For additional help, see:
- MONITORING_DASHBOARD.md - Dashboard documentation
- DEVELOPMENT_PLAN.md - Development roadmap
- README.md - Project overview