Files
route-commerce/src/lib/sentry.ts
T
tyler 6ab52a2499 Production upgrade: Clerk auth, Stripe billing, analytics, PWA support
Backend & Auth:
- Add @clerk/nextjs for production authentication
- Create src/proxy.ts with clerkMiddleware() for route protection
- Implement multi-tenant auth with role-based access control
- Add Clerk components (Show, UserButton, SignInButton, SignUpButton)

Billing & Payments:
- Full Stripe integration (subscriptions, add-ons, customer portal)
- Plan tiers: Starter 9/mo, Farm 49/mo, Enterprise 99/mo
- Webhook handling for subscription events
- createSubscription(), createAddonSubscription(), createCustomerPortalSession()

API & Security:
- Rate limiting with @upstash/ratelimit (100 req/min API, 20 req/min checkout)
- Zod validation schemas for all endpoints (orders, products, campaigns, etc.)
- Security headers (CSP, HSTS, X-Frame-Options)
- API routes: /api/v1/ with validated, rate-limited endpoints

Monitoring:
- Sentry error tracking with performance monitoring
- PostHog analytics for feature usage, funnels, cohorts
- User activity logging and breadcrumb tracking

Admin Features:
- Analytics dashboard with revenue charts, customer growth, conversion funnel
- Onboarding flow with 6-step interactive tour
- Referral system with share tracking and reward redemption
- Changelog feed with in-app notifications

PWA & SEO:
- Web app manifest with icons and shortcuts
- Service worker for offline support and caching
- Full SEO metadata, OpenGraph, Twitter cards
- Structured data (JSON-LD) for organization and products

Database:
- Add referral_codes, changelogs, onboarding_progress tables
- Add user_activity_logs, api_keys, notification_preferences
- Comprehensive RLS policies for all new tables
- Seed data for demo brands and products
2026-06-02 05:33:42 +00:00

75 lines
1.9 KiB
TypeScript

// Sentry configuration for production error monitoring
import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: process.env.SENTRY_DSN,
// Performance monitoring
tracesSampleRate: process.env.NODE_ENV === "production" ? 0.1 : 1.0,
// Environment
environment: process.env.NODE_ENV,
// Release tracking
release: process.env.GIT_SHA || process.env.VERCEL_GIT_COMMIT_SHA,
// Error sampling - capture more errors in production
sampleRate: 1.0,
// Replay sessions for debugging
replaysSessionSampleRate: process.env.NODE_ENV === "production" ? 0.05 : 0,
replaysOnErrorSampleRate: 0.5,
// Ignore common non-actionable errors
ignoreErrors: [
"ResizeObserver loop",
"Non-Error promise rejection captured",
"The operation was aborted",
],
// Tags for filtering in Sentry dashboard
initialScope: {
tags: {
source: "route-commerce",
},
},
// BeforeSend hook for data sanitization
beforeSend(event) {
// Remove any PII or sensitive data before sending
if (event.user) {
delete event.user.ip;
delete event.user.email;
}
return event;
},
});
// Export for manual error capture
export const captureError = (error: Error, context?: Record<string, unknown>) => {
Sentry.captureException(error, {
extra: context,
});
};
// Export for manual breadcrumb logging
export const addBreadcrumb = (message: string, data?: Record<string, unknown>) => {
Sentry.addBreadcrumb({
message,
data,
timestamp: Date.now() / 1000,
});
};
// Export for user tracking during errors
export const setUserContext = (userId: string, brandId?: string) => {
Sentry.setUser({
id: userId,
tags: { brand_id: brandId || "unknown" },
});
};
// Export for transaction tracing
export const startTransaction = (name: string, op: string = "custom") => {
return Sentry.startTransaction({ name, op });
};