Source:
ocean/docs/observability-edge-functions-report.md| ✏️ Edit on GitHub
Edge Functions Observability Integration Report
Overview
This report analyzes the observability integration status of all Edge Functions in the supabase/functions/ directory, focusing on Sentry and PostHog integration.
Summary
Functions with Proper Sentry Integration (10/14)
-
check-tenant-health ✅
- Uses
initSentry()at startup - Uses
Loggerclass for structured logging - Properly tracks errors with
logger.error() - Implements metrics with counters and histograms
- Has trackOperation wrapper for automatic error capture
- Uses
-
GraphQL-v2 ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass for structured logging - Implements
withTracing()wrapper for operations - Properly captures exceptions with context
- Tracks GraphQL operations with spans
- Note: Has comment "PostHog analytics now handled via CDP integration"
- Uses
-
handle-stripe-webhook ✅
- Uses
initSentry()at startup - Uses
Loggerclass for structured logging - Implements metrics (webhookCounter, webhookDuration)
- Uses trackOperation for automatic error tracking
- Properly logs and tracks webhook events
- Uses
-
provision-tenant-resources ✅
- Uses
initSentry()at startup - Uses
Loggerclass with context - Implements tenant provisioning metrics
- Uses trackOperation wrapper
- Properly tracks Neon API calls and provisioning status
- Uses
-
stripe-billing ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass - Implements
withTracing()wrapper for the entire function - Uses
tracedFetch()for external API calls
- Uses
-
stripe-portal ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass - Implements
withTracing()wrapper - Uses
trackSupabaseOperation()for database operations
- Uses
-
stripe-products ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass - Implements
withTracing()wrapper
- Uses
-
stripe-setup-intent ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass - Implements
withTracing()wrapper - Uses
trackSupabaseOperation()for database operations
- Uses
-
stripe-subscription ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass - Implements
withTracing()wrapper - Uses
trackSupabaseOperation()andtracedFetch()
- Uses
-
sync-stripe-data ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass - Implements
withTracing()wrapper - Uses
trackSupabaseOperation()for database operations
- Uses
-
sync-user-to-stripe ✅
- Uses
initSentryWithTracing()for distributed tracing - Uses
Loggerclass - Implements
withTracing()wrapper - Uses Sentry.withScope for detailed error context
- Uses
-
test-sentry ✅
- Uses
initSentry()at startup - Uses
Loggerclass - Designed specifically to test Sentry integration
- Uses
Functions Missing Sentry Integration (2/14)
-
provision-user-resources ❌
- No Sentry import or initialization
- No Logger class usage
- Uses basic console.log for logging
- No error tracking with Sentry.captureException
-
send-slack-alert ❌
- No Sentry import or initialization
- No Logger class usage
- No structured error handling with Sentry
PostHog Integration Status
Current State
- NO functions have direct PostHog integration
- Only
graphql-v2has a comment mentioning: "PostHog analytics now handled via CDP integration" - This suggests PostHog is handled at a different layer (Customer Data Platform)
Functions That Would Benefit from PostHog Analytics
- GraphQL-v2 - Track API usage, query patterns, performance
- stripe-subscription - Track subscription events, conversion rates
- stripe-billing - Track billing operations, payment success rates
- provision-tenant-resources - Track provisioning success/failure rates
- check-tenant-health - Track health check patterns, issues by region
Observability Features Used
Sentry Features
- Basic Error Tracking:
initSentry()- 3 functions - Distributed Tracing:
initSentryWithTracing()- 9 functions - Structured Logging:
Loggerclass - 12 functions - Operation Tracking:
trackOperation()- 3 functions - Traced Operations:
withTracing()- 9 functions - Supabase Operation Tracking:
trackSupabaseOperation()- 6 functions - HTTP Request Tracing:
tracedFetch()- 2 functions
Metrics Implementation
- Custom Prometheus-style metrics in
_shared/observability.ts - Used by: check-tenant-health, handle-stripe-webhook, provision-tenant-resources
- Metrics endpoint exposed at
/metricspath
Recommendations
Immediate Actions
-
Add Sentry to Missing Functions:
// provision-user-resources/index.ts
import { initSentry, Logger } from '../_shared/observability.ts'
initSentry('provision-user-resources')
const logger = new Logger({ functionName: 'provision-user-resources' })// send-slack-alert/index.ts
import { initSentry, Logger } from '../_shared/observability.ts'
initSentry('send-slack-alert')
const logger = new Logger({ functionName: 'send-slack-alert' }) -
Replace console.log with logger:
- provision-user-resources: Replace all
console.logwith appropriatelogger.info/warn/error - send-slack-alert: Add structured logging throughout
- provision-user-resources: Replace all
-
Add Error Tracking:
- Wrap main logic in try-catch blocks
- Use
logger.error()which automatically sends to Sentry - Add context to errors for better debugging
Future Enhancements
-
Standardize Tracing Approach:
- Consider using
initSentryWithTracingfor all functions that make external API calls - Add
withTracingwrapper to functions missing it
- Consider using
-
Enhance Metrics Collection:
- Add metrics to more functions (especially Stripe-related ones)
- Create dashboards for monitoring key metrics
-
PostHog Integration:
- If CDP integration isn't sufficient, consider adding direct PostHog tracking for:
- User actions (subscriptions, billing changes)
- API usage patterns
- Feature adoption metrics
- If CDP integration isn't sufficient, consider adding direct PostHog tracking for:
-
Correlation IDs:
- Add request/correlation IDs to track operations across functions
- Enhance Logger to include correlation IDs automatically
Conclusion
The Edge Functions have good observability coverage with 85% (12/14) having Sentry integration. The two functions missing integration (provision-user-resources and send-slack-alert) should be updated to match the patterns used in other functions. PostHog appears to be handled through a CDP integration rather than direct implementation in Edge Functions.