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:

  1. enable docker

  2. Create a local Supabase project


_10
npx supabase init

  1. create a .env file in the supabase folder

_10
echo "MY_NAME=Some_name" >> ./supabase/.env

  1. deploy the newly added secret

_10
npx supabase secrets set --env-file ./supabase/.env --project-ref <PROJECT REF>

  1. Run the following CLI command to check secrets:

_10
npx 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
_17
console.log('Hello from Functions!')
_17
_17
//custom secret
_17
console.log('logging custom secret', Deno.env.get('MY_NAME'))
_17
_17
// default secrets
_17
console.log('logging SUPABASE_URL:', Deno.env.get('SUPABASE_URL').slice(0, 15))
_17
_17
Deno.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.

image

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.