Debug System
Status: Production-ready debugging infrastructure Last Updated: 2025-11-21 Aligned with: CLAUDE.md Project Values, Best-in-class debugging practicesTable of Contents
- Overview
- Quick Start
- Architecture
- Features
- Usage Guide
- Best Practices
- Integration Examples
- Troubleshooting
Overview
Purpose
The Sanctiv Debug System provides enterprise-grade debugging capabilities with production-safe toggles, structured logging, and automatic Sentry integration. Key Principles:- 100% Excellence - Best-in-class debugging tools
- Simple but not simpler - Powerful yet easy to use
- Production-safe - Disabled by default, no performance impact when off
Why We Built This
Before:- Scattered
console.logstatements - Manual Sentry breadcrumb tracking
- Difficult to debug production issues
- Logs lost on app restart
- Centralized, structured logging
- Automatic Sentry integration
- Persistent debug configuration
- Performance tracking
- Network request monitoring
- State change tracking
Quick Start
Enable Debug Mode
- Open Settings → Debug Mode
- Toggle “Enable Debug Mode” ON
- Configure tracking options:
- ✅ Send Logs to Sentry (recommended for production debugging)
- ✅ Console Logging (for live debugging)
- ✅ Performance Metrics (track slow operations)
- ✅ Network Tracking (log API calls)
- ✅ State Tracking (log Zustand changes)
- ✅ User Interactions (log navigation/clicks)
Use the Logger
Architecture
Components
Data Flow
Features
1. Structured Logging
Log Levels:debug- Verbose development informationinfo- State changes, user actions, API callswarn- Recoverable errors, performance issueserror- Exceptions, failed operations
2. Automatic Sentry Integration
When “Send Logs to Sentry” is enabled:- ✅ All logs → Sentry breadcrumbs
- ✅ Errors → Sentry issues
- ✅ Context preserved for debugging
- ✅ No code changes required
3. Performance Monitoring
Track operation timing:4. Network Request Tracking
Automatic fetch monitoring when enabled:5. State Change Tracking
Monitor Zustand store updates:6. User Interaction Tracking
Log navigation and clicks:7. Persistent Configuration
Debug settings persist across app restarts via AsyncStorage:- Enabled/disabled state
- Log level
- Sentry integration toggle
- Feature flags (performance, network, state, user tracking)
8. Log Export
Export logs for sharing with team:- Settings → Debug Mode → Export Logs
- Logs copied as JSON
- Share via email/Slack/GitHub issue
8. Version Signature System
Format Philosophy:VERSION (BUILD:OTA)
The version signature uniquely identifies the exact state of the app:
Components:
- VERSION = What the app is (semantic version:
1.0.4) - BUILD = TestFlight binary number (unique identifier:
37) - OTA = Over-the-air update commit hash (first 3 chars:
c07)
- Version is the primary identifier (what users care about)
- Build:OTA grouping shows delivery method (how they got it)
- Build number uniquely identifies the binary (no need for redundant binary commit hash)
- OTA commit shows what’s actually running (JavaScript/UI code)
Usage Guide
Basic Logging
Component Logging
Performance Tracking
Grouped Logs
For multi-step operations:Log Levels
Choose appropriate level:Best Practices
1. Use Descriptive Categories
Good:2. Include Actionable Context
Good:3. Don’t Log Sensitive Data
Never log:- Passwords
- API keys
- Authentication tokens
- Credit card numbers
- Personal health information (PHI)
- User IDs (hashed if needed)
- Error messages
- Timestamps
- Feature flags
- Navigation paths
4. Use Performance Tracking Sparingly
Only track operations that:- Are user-facing (load times, UI interactions)
- Are known to be slow
- Are being optimized
5. Clean Up Old Logs
Logs are kept in memory (last 100). Use “Clear Debug Logs” regularly to free memory.6. Disable in Production (Users)
Debug mode should be OFF by default for end users. Only enable for:- Development
- Internal testing
- Troubleshooting specific user issues
Integration Examples
Flow Engine Integration
API Integration
State Store Integration
Troubleshooting
Issue: Logs not appearing in console
Check:- Debug Mode enabled? (Settings → Debug Mode)
- Console Logging enabled?
- Log level correct? (DEBUG shows all, ERROR shows only errors)
Issue: Logs not appearing in Sentry
Check:- “Send Logs to Sentry” enabled?
- Sentry DSN configured? (EXPO_PUBLIC_SENTRY_DSN)
- Network connectivity?
Issue: Performance impact
Solution:- Disable debug mode in production
- Reduce log level to “warn” or “error”
- Disable performance tracking when not needed
Issue: Logs filling memory
Logs are capped at 100 entries. To manually clear:Next Steps
Planned Enhancements
- Clipboard Integration - Copy exported logs automatically
- Share Dialog - Email/Slack logs directly from app
- Visual Log Viewer - In-app log browser UI
- Supabase Query Tracking - Deep Supabase monitoring
- Redux DevTools Integration - Time-travel debugging
- Remote Logging - Send logs to custom endpoint
Contributing
To add new logging features:- Update
debugStore.tsfor new config options - Update
logger.tsfor new logging methods - Update Settings UI for new toggles
- Document in this file
Resources
Internal Files
- src/lib/logger.ts - Core logging API
- src/state/debugStore.ts - Debug configuration
- src/lib/debugNetworkMonitor.ts - Network tracking
- src/screens/SettingsScreen.tsx - Debug Mode UI
Related Documentation
- SENTRY.md - Sentry error monitoring
- STATE_MANAGEMENT.md - Zustand patterns
- TESTING.md - E2E testing with Maestro
- ARCHITECTURE.md - System architecture
Maintained by: Development Team
Questions? Check CLAUDE.md or Slack #dev-support