Inspecting edge function environment variables
Last edited: 1/17/2025
Sometimes it can be informative to log values from your Edge Functions. This walks you through the process of logging environment variables for inspection, but it can be generalized for all logging.
Steps:
-
enable docker
-
Create a local Supabase project
_10npx supabase init
- create a .env file in the supabase folder
_10echo "MY_NAME=Some_name" >> ./supabase/.env
- deploy the newly added secret
_10npx supabase secrets set --env-file ./supabase/.env --project-ref <PROJECT REF>
- Run the following CLI command to check secrets:
_10npx supabase secrets list
For security reasons, it is not advised to log secrets, but you can log a truncated version just for the reassurance that they're being updated:
_17//logs the function call and the secrets_17console.log('Hello from Functions!')_17_17//custom secret_17console.log('logging custom secret', Deno.env.get('MY_NAME'))_17_17// default secrets_17console.log('logging SUPABASE_URL:', Deno.env.get('SUPABASE_URL').slice(0, 15))_17_17Deno.serve(async (req) => {_17 const { name } = await req.json()_17 const data = {_17 message: `Hello ${name}!`,_17 }_17_17 return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })_17})
After calling your function, you can check your edge function logs to observe the logged values. It should look something like this:
Note: search filters are case sensitive and must be present in the event message.
Note: excessively long JSON logs may be truncated. If this occurs, use the JSON.stringify() function to convert the JSON object into text. You can then copy and paste the log into a JSON beautifier.