Source:
ocean/docs/slack-integration-quickstart.md| ✏️ Edit on GitHub
Slack Integration Quick Start Guide
This is a condensed guide to get Slack notifications working quickly with Ocean.
Step 1: Create Slack App (5 minutes)
- Go to API.slack.com/apps
- Click "Create New App" → "From scratch"
- Name: "Ocean Alerts", select your workspace
- Go to "Incoming Webhooks" → Toggle ON
- Click "Add New Webhook to Workspace"
- Create these channels and add webhooks:
#alerts-critical#alerts-errors#alerts-performance#alerts-analytics
Step 2: Add Webhook URLs to Environment
Add to your .env.local (for local testing):
# Slack Webhooks
SLACK_WEBHOOK_CRITICAL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
SLACK_WEBHOOK_ERRORS=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
SLACK_WEBHOOK_PERFORMANCE=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
SLACK_WEBHOOK_ANALYTICS=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
Add to Supabase Edge Function secrets:
supabase secrets set SLACK_WEBHOOK_CRITICAL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
supabase secrets set SLACK_WEBHOOK_ERRORS=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
supabase secrets set SLACK_WEBHOOK_PERFORMANCE=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
supabase secrets set SLACK_WEBHOOK_ANALYTICS=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
Step 3: Deploy Slack Alert Function
# Deploy the Edge Function
supabase functions deploy send-slack-alert
Step 4: Configure Sentry
- Go to Sentry → Settings → Integrations
- Install Slack integration
- Create alert rules:
Critical pg_net Alert
Name: 'pg_net Critical Backlog'
Conditions:
- When: An event is seen
- Filters:
- message CONTAINS "pg_net backlog"
- tags.pg_net_status = critical
Actions:
- Send to Slack #alerts-critical
High Error Rate
Name: 'High Error Rate'
Conditions:
- When: Error rate > 5%
- For: 10 minutes
Actions:
- Send to Slack #alerts-errors
Step 5: Configure PostHog
- Go to PostHog → Apps
- Install "Slack" app
- Configure webhook URL
- Create actions:
New User Signup
{
"event": "user_signed_up",
"slack_channel": "#alerts-analytics",
"message": "🎉 New user: {{person.email}}"
}
Step 6: Test Your Integration
Test from your app
import { sendSlackAlert } from '@/lib/slack-alerts'
// Test critical alert
await sendSlackAlert({
type: 'test',
level: 'critical',
message: '🧪 Test critical alert - ignore',
details: {
test: true,
timestamp: new Date().toISOString(),
},
})
// Test Sentry integration
Sentry.captureMessage('Test Sentry Slack integration', {
level: 'error',
tags: { test: true },
})
// Test PostHog integration
posthog.capture('test_slack_event', {
test: true,
channel: '#alerts-analytics',
})
Test pg_net monitoring
-- Trigger a test pg_net alert
INSERT INTO monitoring.pg_net_health (
queue_size, response_size, status
) VALUES (
15000, 60000, 'critical'
);
Common Webhook Formats
Error Alert
{
"text": "🚨 Critical Error",
"attachments": [
{
"color": "danger",
"title": "Database Connection Failed",
"fields": [
{ "title": "Error", "value": "Connection timeout", "short": true },
{ "title": "Time", "value": "2024-01-20 15:30:00", "short": true }
]
}
]
}
Performance Alert
{
"text": "⚠️ Performance Warning",
"attachments": [
{
"color": "warning",
"title": "Slow Query Detected",
"fields": [
{ "title": "Query Time", "value": "5.2s", "short": true },
{ "title": "Table", "value": "organizations", "short": true }
]
}
]
}
Troubleshooting
"Invalid webhook URL"
- Check URL format: must start with
https://hooks.slack.com/services/ - Verify webhook is active in Slack app settings
"No messages appearing"
- Check Supabase Edge Function logs:
supabase functions logs send-slack-alert - Verify environment variables are set
- Test webhook directly:
curl -X POST -d '{"text":"test"}' YOUR_WEBHOOK_URL
"Rate limited by Slack"
- Implement batching for similar alerts
- Use the rate limiter in
slack-alerts.ts - Consider using threads for related alerts
Next Steps
- Set up alert aggregation - Prevent spam during incidents
- Create runbooks - Link alerts to fix procedures
- Add PagerDuty - For critical after-hours alerts
- Custom formatting - Enhance message appearance
Quick Reference
Send alerts from your app
import { sendCriticalAlert, sendPerformanceAlert } from '@/lib/slack-alerts'
// Critical alert
await sendCriticalAlert('Payment Failed', 'Stripe webhook error', {
error: 'Invalid webhook signature',
customer_id: 'cus_123',
})
// Performance alert
await sendPerformanceAlert('Slow API Response', {
metric: 'api_response_time',
value: 5200,
threshold: 3000,
endpoint: '/api/billing',
})
Alert levels
critical→ #alerts-critical (immediate action needed)error→ #alerts-errors (errors that need investigation)warning→ #alerts-performance (performance issues)info→ #alerts-analytics (metrics, user events)