Skip to content
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

feat: add region and instance id to logger #142

Merged
merged 7 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.21
0.2.22
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config :supavisor, SupavisorWeb.Endpoint,
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id, :project, :user]
metadata: [:request_id, :project, :user, :region, :instance_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
Expand Down
11 changes: 11 additions & 0 deletions lib/supavisor/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ defmodule Supavisor.Application do

@impl true
def start(_type, _args) do
primary_config = :logger.get_primary_config()

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

:ok =
:gen_event.swap_sup_handler(
:erl_signal_server,
Expand Down
1 change: 1 addition & 0 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ defmodule Supavisor.ClientHandler do
hello = decode_startup_packet(bin)
Logger.debug("Client startup message: #{inspect(hello)}")
{user, external_id} = parse_user_info(hello.payload["user"])

abc3 marked this conversation as resolved.
Show resolved Hide resolved
Logger.metadata(project: external_id, user: user)

sni_hostname = try_get_sni(sock)
Expand Down
1 change: 1 addition & 0 deletions lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@impl true
def init(args) do
Process.flag(:trap_exit, true)

abc3 marked this conversation as resolved.
Show resolved Hide resolved
Logger.metadata(project: args.tenant, user: args.user_alias)

data = %{
Expand Down Expand Up @@ -74,7 +75,7 @@
case try_ssl_handshake({:gen_tcp, sock}, auth) do
{:ok, sock} ->
# TODO: fix user name
case send_startup(sock, auth) do

Check warning on line 78 in lib/supavisor/db_handler.ex

View workflow job for this annotation

GitHub Actions / Formatting Checks

Function body is nested too deep (max depth is 2, was 3).
:ok ->
:ok = activate(sock)
{:next_state, :authentication, %{data | sock: sock}}
Expand Down
1 change: 1 addition & 0 deletions lib/supavisor/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule Supavisor.Manager do
}

Logger.metadata(project: args.tenant, user: args.user_alias)

abc3 marked this conversation as resolved.
Show resolved Hide resolved
Registry.register(Supavisor.Registry.ManagerTables, {args.tenant, args.user_alias}, tid)

{:ok, state}
Expand Down
Loading