Debugging Edge Functions
Debugging tips and Edge Function limitations.
Logs & debugging#
Logs are provided for each function invocation, locally and in production.
Any uncaught exceptions thrown by a function during the execution will be automatically logged.
You can also use console.log
, console.error
, and console.warn
in your code to emit custom log events.
A custom log message can contain up to 10,000 characters. A function can log up to 100 events within a 10 second period.
Debugging in production#
You can debug your deployed Edge Functions using the "Functions" section of the Dashboard. There are two debugging tools available:
- Invocations: shows the Request and Response for each execution.
- Logs: shows any platform events, uncaught exceptions, and custom log events.
Debugging locally#
When developing locally you will see error messages and console log statements printed to your local terminal window.
Limitations#
- Outgoing connections to ports
25
,465
, and587
are not allowed. - Serving of HTML content is not supported (
GET
requests that returntext/html
will be rewritten totext/plain
). - Deno FileSystem APIs are not available to use within Edge Functions.
- Importing modules using
npm:
specifier is currently not supported (use a CDN to load npm modules).
Troubleshooting#
Unable to call Edge Function#
If you're unable to call your Edge Function or are experiencing any CORS issues:
- Make sure you followed the CORS guide.
- Check your function logs. Navigate to the Functions section in your dashboard, select your function from the list, and click
Logs
. Check for any errors.
There are two debugging tools available: Invocations and Logs. Invocations shows the Request and Response for each execution, while Logs shows any platform events, including deployments and errors.
Unable to deploy Edge Function#
- Make sure you're on the latest version of the Supabase CLI.
- Run the deploy command with the
--debug
flag. - Run the deploy command with the
--legacy-bundle
flag. - If the output from the commands above does not help you to resolve the issue, open a support ticket via the Supabase Dashboard (by clicking the "Help" button at the top right) and include all output from the commands mentioned above.
Edge Function takes too long to respond#
- Navigate to the Functions section in your Supabase dashboard, select your function from the list, and click
Logs
. - In the logs, look for the
booted
event and check if they have consistent boot times.- If the boot times are similar, it's likely an issue with your function's code, such as a large dependency.
- If only some of the
booted
events are slow, find the affectedregion
in the metadata and submit a support request via the "Help" button at the top.
Issues serving Edge Functions locally with the Supabase CLI#
- Make sure you're on the latest version of the Supabase CLI.
- Run the serve command with the
--debug
flag. - Support engineers can then try to run the provided sample code locally and see if they can reproduce the issue.
- Search the Edge Runtime and CLI repos for the error message, to see if it has been reported before.
- If the output from the commands above does not help you to resolve the issue, please open a support ticket via the Supabase Dashboard (by clicking the "Help" button at the top right) and include all output and details about your commands.
Advanced techniques#
Checking function boot time#
Check the logs for the function. In the logs, look for a "Booted" event and note the reported boot time. If available, click on the event to access more details, including the regions from where the function was served. Investigate if the boot time is excessively high (longer than 1 second) and note any patterns or regions where it occurs.
Finding bundle size#
To find the bundle size of a function, run the following command locally:
_10deno info /path/to/function/index.ts
Look for the "size" field in the output which represents the approximate bundle size of the function.You can find the accurate bundle size when you deploy your function via Supabase CLI. If the function is part of a larger application, consider examining the bundle size of the specific function independently.
Analyze dependencies#
Run deno info
, providing the path to your input map if you use one.
Review the dependencies listed in the output. Pay attention to any significantly large dependencies, as they can contribute to increased bundle size and potential boot time issues.
Examine if there are any unnecessary or redundant dependencies that can be removed. Check for outdated dependencies and update to the latest versions if possible.
_10deno info --import-map=/path/to/import_map.json /path/to/function/index.ts