/admin/monitoring provides a real-time view of system health: live connected users via Supabase Realtime presence, a streaming log panel with 5-second refresh, KPI counters for errors/warnings, and a health pulse indicator.
AdminMonitoring Page Structure
MonitoringHeader
Shows online user count, error count, and warning count. Color-coded by severity.
MonitoringStatsGrid
Four KPI cards: Online Users, Total Errors, Total Warnings, Total Info Logs.
LiveUsersPanel
Real-time list of active users via Supabase Realtime presence. Shows email, current path, and session start time.
HealthPulse
Heartbeat indicator. Green = no errors. Session uptime counter in minutes.
SystemLogsPanel
Streams the last 50
app_logs entries, auto-refreshing every 5 seconds. Filterable by log level.Sentry Integration
Sentry is initialized inmonitoring.service.ts via initMonitoring(), called from main.tsx at app startup:
Sentry is loaded dynamically (not in the initial bundle) to avoid adding ~80–120 kB to the main chunk. It only initializes in
PROD when VITE_SENTRY_DSN is set.| Configuration | Value |
|---|---|
tracesSampleRate | 1.0 — 100% of transactions |
browserTracingIntegration | Enabled |
| Environment | Production only (import.meta.env.PROD) |
| Activation | Requires VITE_SENTRY_DSN env variable |
Manual Error Capture
logError writes to both Supabase app_logs and Sentry simultaneously:
- Supabase: inserts a row into
app_logswith level'error', category, message, stack trace, and URL - Sentry: calls
Sentry.captureExceptionwith the category as a tag and extra details
Google Analytics 4
GA4 is loaded via script tag inindex.html with measurement ID G-XXXXXXXXXX (must be replaced with the real ID before production).
E-commerce Events
All events are implemented insrc/lib/analytics.ts:
| GA4 Event | Trigger |
|---|---|
view_item | Product detail page load |
add_to_cart | Item added to cart via cart.store.addItem() |
begin_checkout | Checkout page opened |
purchase | Order successfully created |
ai_* | AI interaction events via trackAIInteraction() |
useAppMonitoring Hook
TheuseAppMonitoring hook is called in App.tsx to wire up presence tracking and global error capture for the entire session:
- Presence channel is created once per session when the user first visits
/admin - On each admin route navigation,
trackPresenceActivityupdates the user’s current path - The channel is automatically unsubscribed when navigating away from admin
- Global
window.errorandwindow.unhandledrejectionevents are captured and sent tologError()
Supabase Realtime Presence
The monitoring page subscribes to thestore_monitoring Realtime channel:
App Logs (Supabase)
Logs are stored in theapp_logs table and streamed to SystemLogsPanel every 5 seconds:
logToSupabase(log) automatically appends user_agent and current window.location.href.
Health Status Calculation
TheHealthPulse component and sidebar monitoring indicator derive system health from log data:
isSystemHealthy = true→ Green pulse, “Sistema OK”isSystemHealthy = false→ Red pulse, error count displayed
