Skip to main content

Monitoring & Health

How to monitor the Client Portal platform and respond to common operational issues.

System Health Check

The check-data-readiness edge function provides a quick health check across core system components:

curl -X POST \
https://<supabase-url>/functions/v1/check-data-readiness \
-H "Authorization: Bearer <service-role-key>"

This checks:

  • Database connectivity
  • Key table row counts
  • Edge function availability
  • Integration token validity

Monitoring Dashboards

Supabase Dashboard

Access at https://supabase.com/dashboard/project/<project-id>.

Key sections to monitor:

SectionWhat to Check
Database > TablesRow counts for core tables (attorneys, sales_prospects, calls, sales_calls)
Database > Query PerformanceSlow queries, missing indexes
Edge Functions > LogsFunction invocations, errors, response times
Auth > UsersActive user count, failed login attempts
Storage > Bucketscall-recordings bucket size and usage

Edge Function Logs

Navigate to Supabase Dashboard > Edge Functions > select function > Logs.

Filter by:

  • Status code -- Look for 4xx/5xx errors
  • Duration -- Identify slow-running functions
  • Timestamp -- Correlate with reported issues

Key Metrics to Watch

Webhook Success Rate

Monitor the ratio of successful webhook processing to total incoming webhooks.

Where to check: Query webhook_debug_log for recent entries:

-- Webhook success rate (last 24 hours)
SELECT
count(*) FILTER (WHERE status = 'success') AS successes,
count(*) FILTER (WHERE status = 'error') AS errors,
count(*) AS total
FROM webhook_debug_log
WHERE created_at > now() - interval '24 hours';

Healthy: >95% success rate. If errors spike, check edge function logs for the specific webhook handler.

AI Summarization Queue

Calls with transcripts >100 chars should have ai_summary populated within minutes.

-- Calls awaiting summarization (should be near zero)
SELECT count(*)
FROM sales_calls
WHERE transcript IS NOT NULL
AND length(transcript) > 100
AND ai_summary IS NULL
AND created_at > now() - interval '1 hour';

If this number is growing, check:

  1. ANTHROPIC_API_KEY is still valid as a Supabase secret
  2. summarize-sales-call edge function logs for errors
  3. Anthropic API status page for outages

Calendar Token Expiration

OAuth tokens expire and need refreshing. Monitor for upcoming expirations:

-- Client calendar tokens expiring within 24 hours
SELECT client_id, provider, token_expires_at
FROM calendar_connections
WHERE token_expires_at < now() + interval '24 hours'
AND is_active = true;

-- Internal user calendar tokens expiring within 24 hours
SELECT user_id, provider, token_expires_at
FROM user_calendar_connections
WHERE token_expires_at < now() + interval '24 hours'
AND is_active = true;

Tokens are refreshed automatically during calendar operations, but if a client has not used the system in a while, their token may have expired without being refreshed.

Enrichment Credit Balance

Check remaining Blitz API credits:

curl -H "x-api-key: $BLITZ_API_KEY" https://api.blitz-api.ai/api/blitz/key-info

Healthy: Sufficient credits for planned enrichment runs. Budget 2--7 credits per attorney.

Common Alerts and Responses

Failed Webhooks

Symptom: Calls made in GHL are not appearing in Client Portal.

Diagnose:

  1. Check webhook_debug_log for recent entries with errors
  2. Check edge function logs for ghl-call-webhook and ghl-sales-webhook
  3. Verify GHL workflow is still active and pointing to the correct URL

Fix: Usually caused by edge function deployment issues or GHL API token expiry. Redeploy the function or update the token in ghl_integrations.

OAuth Token Expiry

Symptom: Calendar availability checks return errors. Booking pages show "unavailable."

Diagnose:

SELECT * FROM calendar_connections WHERE token_expires_at < now();
SELECT * FROM user_calendar_connections WHERE token_expires_at < now();

Fix: The client or user needs to re-authorize their calendar connection. Navigate to account settings and click the reconnect button. The OAuth callback will store fresh tokens.

Blitz API Rate Limiting

Symptom: Enrichment script returns 429 errors or empty responses.

Diagnose: Check the script output for rate limit warnings. Also check remaining credits via the key-info endpoint.

Fix:

  1. Wait 5--10 minutes for rate limits to reset
  2. Increase delay between requests if needed (current: 700ms between attorneys, 3s between firms)
  3. If credits are exhausted, contact Blitz API support or upgrade the plan

Edge Function Timeout

Symptom: Edge function returns 504 or function logs show timeout.

Diagnose: Check function logs for the specific function. Edge functions have a default timeout of 60 seconds.

Fix:

  1. For long-running operations, break them into smaller batches
  2. Check if the function is waiting on an unresponsive external API
  3. Verify the function is not caught in an infinite loop

Health Check Schedule

CheckFrequencyHow
Webhook success rateDailyQuery webhook_debug_log
AI summarization queueDailyQuery sales_calls for unsummarized calls
Calendar token expiryWeeklyQuery both calendar connection tables
Enrichment credit balanceBefore each enrichment runBlitz API key-info endpoint
Edge function error rateWeeklySupabase dashboard edge function logs
Database sizeMonthlySupabase dashboard database metrics