Source:
ocean/docs/sentry-configuration-guide.md| ✏️ Edit on GitHub
Comprehensive Sentry Configuration Guide
This guide documents our complete Sentry setup, including all configurations, best practices, and monitoring strategies.
Table of Contents
- Overview
- Frontend Configuration
- Edge Functions Configuration
- Database Monitoring
- Alert Rules
- Security & Privacy
- Performance Optimization
- Troubleshooting
Overview
Our Sentry implementation provides comprehensive observability across:
- Frontend React application
- Supabase Edge Functions
- Database operations
- User journeys and interactions
Key Features
- Cost-optimized for Sentry Team plan limits
- Privacy-first with no PII collection by default
- Performance monitoring with INP and Core Web Vitals
- Distributed tracing across frontend and backend
- Custom instrumentation for business metrics
Frontend Configuration
Initialization
The Sentry SDK is initialized in src/lib/sentry.tsx with:
// Production sampling rates (cost-optimized)
tracesSampleRate: 0.2 // 20% of transactions
replaysSessionSampleRate: 0.05 // 5% of sessions
replaysOnErrorSampleRate: 1.0 // 100% on errors
profilesSampleRate: 0.05 // 5% of transactions
Error Filtering
We filter out common noise:
- Browser extension errors
- ResizeObserver warnings
- Network timeouts from third-party scripts
- Non-critical console messages
Custom Integrations
- Browser Tracing - Monitors API calls, navigation, and user interactions
- Session Replay - Records user sessions with privacy masking
- Profiling - Identifies performance bottlenecks
Edge Functions Configuration
Each Edge Function includes Sentry monitoring via _shared/observability.ts:
Features
- Distributed tracing with frontend correlation
- Structured logging with JSON output
- Custom metrics collection (Prometheus-style)
- Error context with request details
Usage Example
import { Logger } from '../_shared/observability.ts'
import { withTracing } from '../_shared/sentry-tracing.ts'
const logger = new Logger({ functionName: 'my-function' })
serve(
withTracing('my-function', async (req) => {
logger.info('Processing request', { method: req.method })
// Function logic
})
)
Database Monitoring
Query Performance Tracking
The sentry-database-monitoring.ts module wraps Supabase client to track:
- Query execution times
- Slow queries (>1 second)
- Failed queries with error context
- Auth operations
Database Schema Monitoring
The monitoring schema tracks:
- Slow query patterns
- Trigger execution performance
- Webhook delivery attempts
Automated Alerts
The MonitoringAlertSystem checks every 5 minutes for:
- Queries averaging >5 seconds
- Database trigger failures
- Webhook success rates <95%
Alert Rules
Configure these rules in your Sentry dashboard:
Critical Alerts (Immediate Action)
- Payment Failures - Any Stripe/billing errors
- Security Violations - Auth failures, suspicious activity
- Data Integrity - Database constraint violations
- API Downtime - 500/503 errors exceeding threshold
Warning Alerts (Investigation Required)
- High Error Rate - >50 errors in 5 minutes
- Slow Transactions - p95 >3 seconds
- Memory Leaks - Heap usage >90%
- Low Crash-Free Rate - <95% sessions
Informational Alerts
- User Experience - INP >500ms
- Rate Limiting - Frequent rate limit hits
- Third-Party Failures - External API issues
Security & Privacy
Data Sanitization
- No PII collected by default (
sendDefaultPii: false) - Sensitive headers redacted in Edge Functions
- Password fields masked in replays
- API keys filtered from error context
Production Protection
- Sentry removed from window object in production
- Console methods overridden to prevent logging
- Source maps uploaded but not exposed publicly
Compliance
- GDPR compliant with user consent for email collection
- Data retention policies aligned with privacy requirements
- User deletion propagated to Sentry
Performance Optimization
Sampling Strategy
// Dynamic sampling based on importance
if (isPaymentFlow) {
Sentry.getCurrentHub().getScope()?.setTransactionSampleRate(1.0)
}
Rate Limiting
Custom rate limiter prevents flooding:
rateLimitedCaptureException(error) // Max 10 per minute per error type
Memory Monitoring
Automatic heap size monitoring with alerts:
startMemoryMonitoring() // Checks every 30 seconds
Troubleshooting
Common Issues
-
Missing Source Maps
- Verify
SENTRY_AUTH_TOKENin CI/CD - Check Vite build configuration
- Ensure release version matches
- Verify
-
No Errors Appearing
- Verify DSN configuration
- Check browser console for initialization errors
- Ensure not filtered by
beforeSend
-
High Quota Usage
- Review sampling rates
- Check for error loops
- Enable rate limiting
Debug Mode
In development:
window.Sentry.captureException(new Error('Test'))
window.Sentry.showReportDialog()
Verification
Test your setup:
- Navigate to
/admin/sentry-debug - Click "Test Error Handling"
- Verify error appears in Sentry dashboard
Maintenance
Regular Tasks
-
Weekly
- Review error trends
- Check quota usage
- Update ignore patterns
-
Monthly
- Analyze performance metrics
- Review alert thresholds
- Clean up resolved issues
-
Quarterly
- Update SDK version
- Review sampling rates
- Audit security settings