Skip to content

This PR adds region and instance ID #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LogProphet
Copy link

What kind of change does this PR introduce?

Feature: Adds region and instance_id to logger metadata (#627)


What is the current behavior?

This metadata is currently not included in logs, as described in issue #627.


What is the new behavior?

Adds region and instance_id metadata to the logger using values from the environment:

System.get_env("REGION")
System.get_env("INSTANCE_ID")

This allows these fields to be available in log output for observability and debugging.


Additional context

I also considered adding a helper to make required env vars safer and more expressive:

defp require_env!(key) do
  case System.get_env(key) do
    nil -> raise "Required environment variable #{key} is not set"
    val -> val
  end
end

Which would allow replacing direct System.get_env/1 calls with:

Enum.into(
  [region: require_env!("REGION"), instance_id: require_env!("INSTANCE_ID")],
  primary_config.metadata
)

I also briefly considered defaulting to safe fallbacks in dev/test environments:

:ok =
  :logger.set_primary_config(
    :metadata,
    Enum.into(
      [
        region: System.get_env("REGION") || "unknown",
        instance_id: System.get_env("INSTANCE_ID") || "local"
      ],
      primary_config.metadata
    )
  )

But I wasn't sure if that was necessary, or if it might obscure misconfigured environments. If preferred, I’m happy to incorporate either approach. 😊

to the logger metadata, per issue supabase#627
Copy link

vercel bot commented Apr 13, 2025

@ThatJSGuy is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant