Skip to main content

Overview

Debugging Edge Functions involves viewing logs, testing locally, handling errors, and monitoring performance. This guide covers tools and techniques to help you identify and fix issues quickly.

Viewing Logs

CLI Logs

View real-time logs for a function:
View logs with tail:
This streams logs in real-time as requests come in.

Filter Logs

Filter logs by time range:

Dashboard Logs

View logs in the Supabase Dashboard:
  1. Go to Edge Functions in your project
  2. Click on your function
  3. Navigate to the Logs tab
The dashboard provides:
  • Searchable logs
  • Log level filtering (info, warn, error)
  • Request/response inspection
  • Performance metrics

Local Development

Serve Locally

Run functions locally for easier debugging:
With environment variables:
Skip JWT verification for testing:

Hot Reload

Changes are automatically reloaded when you save files:

Debug with Deno

Use Deno’s built-in debugger:
Then connect with Chrome DevTools:
  1. Open chrome://inspect in Chrome
  2. Click “inspect” under your function
  3. Set breakpoints and step through code

Console Logging

Basic Logging

Use console.log() for debugging:

Log Levels

Use different log levels:

Structured Logging

Log structured data for better analysis:

Error Handling

Try-Catch Blocks

Always wrap async operations:

Custom Error Classes

Create custom error types:

Error Response Helper

Create a reusable error handler:

Testing Functions

Manual Testing with curl

Test locally:
Test production:

Automated Tests

Create test files:
Run tests:

Integration Tests

Test with database interactions:

Performance Monitoring

Measure Execution Time

Track function performance:

Profile Slow Operations

Identify bottlenecks:

Memory Usage

Monitor memory usage:

Common Issues

Function Timeout

If functions timeout:
  1. Check execution time limits:
    • Free tier: 10 seconds
    • Pro tier: 150 seconds
  2. Optimize slow operations:
  3. Use streaming for large responses

CORS Errors

Fix CORS issues:

Authentication Errors

Debug auth issues:

Cold Starts

Minimize cold start latency:
  1. Keep functions small - Remove unnecessary dependencies
  2. Lazy load modules - Import only when needed
  3. Cache expensive operations - Use module-level caching

Monitoring Tools

Dashboard Metrics

View metrics in the Dashboard:
  1. Go to Edge Functions > Your function
  2. Check the Metrics tab for:
    • Invocation count
    • Error rate
    • Average execution time
    • Memory usage

Custom Monitoring

Send metrics to external services:

Best Practices

  1. Use structured logging for easier analysis
  2. Add request IDs to trace requests through logs
  3. Handle errors gracefully with proper status codes
  4. Test locally first before deploying
  5. Monitor performance regularly
  6. Set up alerts for error rates
  7. Use version control to track changes
  8. Document function behavior for your team

Next Steps

Deploy Functions

Learn deployment strategies and CI/CD

Environment Variables

Manage secrets and configuration

Resources