This commit is contained in:
@@ -4,6 +4,14 @@ defmodule ElixirAi.Application do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
|
# Attach telemetry handler to filter health check logs
|
||||||
|
:telemetry.attach(
|
||||||
|
"filter-health-logs",
|
||||||
|
[:phoenix, :endpoint, :stop],
|
||||||
|
&filter_health_logs/4,
|
||||||
|
nil
|
||||||
|
)
|
||||||
|
|
||||||
children = [
|
children = [
|
||||||
ElixirAiWeb.Telemetry,
|
ElixirAiWeb.Telemetry,
|
||||||
ElixirAi.Repo,
|
ElixirAi.Repo,
|
||||||
@@ -39,4 +47,14 @@ defmodule ElixirAi.Application do
|
|||||||
ElixirAiWeb.Endpoint.config_change(changed, removed)
|
ElixirAiWeb.Endpoint.config_change(changed, removed)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Filter health check requests from telemetry logs
|
||||||
|
defp filter_health_logs(_event, _measurements, %{conn: %{request_path: "/health"}}, _config) do
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
defp filter_health_logs(event, measurements, metadata, config) do
|
||||||
|
# Forward to default Phoenix logger
|
||||||
|
:telemetry.execute(event, measurements, metadata)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ defmodule ElixirAiWeb.Endpoint do
|
|||||||
cookie_key: "request_logger"
|
cookie_key: "request_logger"
|
||||||
|
|
||||||
plug Plug.RequestId
|
plug Plug.RequestId
|
||||||
|
|
||||||
plug Plug.Logger, log: :info, filter: &ElixirAiWeb.Endpoint.filter_health_check/1
|
|
||||||
|
|
||||||
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
|
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
|
||||||
|
|
||||||
plug Plug.Parsers,
|
plug Plug.Parsers,
|
||||||
@@ -52,8 +49,4 @@ defmodule ElixirAiWeb.Endpoint do
|
|||||||
plug Plug.Head
|
plug Plug.Head
|
||||||
plug Plug.Session, @session_options
|
plug Plug.Session, @session_options
|
||||||
plug ElixirAiWeb.Router
|
plug ElixirAiWeb.Router
|
||||||
|
|
||||||
# Filter health check requests from logs
|
|
||||||
def filter_health_check(%{request_path: "/health"}), do: false
|
|
||||||
def filter_health_check(_), do: :info
|
|
||||||
end
|
end
|
||||||
|
|||||||
15
lib/elixir_ai_web/health_check_filter.ex
Normal file
15
lib/elixir_ai_web/health_check_filter.ex
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule ElixirAiWeb.HealthCheckFilter do
|
||||||
|
@moduledoc """
|
||||||
|
Logger filter to suppress health check endpoint logs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def filter(%{meta: meta}, _config) when is_map(meta) do
|
||||||
|
if Map.get(meta, :health_check) == true do
|
||||||
|
:stop
|
||||||
|
else
|
||||||
|
:ignore
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter(_log_event, _config), do: :ignore
|
||||||
|
end
|
||||||
19
lib/elixir_ai_web/plugs/health_check_logger.ex
Normal file
19
lib/elixir_ai_web/plugs/health_check_logger.ex
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
defmodule ElixirAiWeb.Plugs.HealthCheckLogger do
|
||||||
|
@moduledoc """
|
||||||
|
Plug that marks health check requests for filtering.
|
||||||
|
"""
|
||||||
|
@behaviour Plug
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init(opts), do: opts
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def call(%Plug.Conn{path_info: ["health"]} = conn, _opts) do
|
||||||
|
# Mark this as a health check for logger filtering
|
||||||
|
Logger.metadata(health_check: true)
|
||||||
|
conn
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(conn, _opts), do: conn
|
||||||
|
end
|
||||||
3
mix.exs
3
mix.exs
@@ -58,7 +58,8 @@ defmodule ElixirAi.MixProject do
|
|||||||
{:bandit, "~> 1.5"},
|
{:bandit, "~> 1.5"},
|
||||||
{:ecto_sql, "~> 3.11"},
|
{:ecto_sql, "~> 3.11"},
|
||||||
{:postgrex, ">= 0.0.0"},
|
{:postgrex, ">= 0.0.0"},
|
||||||
{:horde, "~> 0.9"}
|
{:horde, "~> 0.9"},
|
||||||
|
{:credo, "~> 1.7", only: [:dev, :test], runtime: false}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user