fix(logs): add Plug.Telemetry metadata filter to suppress health check logs

The FilterNoisyLogs plug wasn't completely preventing logs in Phoenix 1.8.
Added metadata_filter to Plug.Telemetry to explicitly skip logging for:
- GET /health
- GET /health/time
- HEAD /

This works at the Telemetry level before logs are emitted.
This commit is contained in:
Graham McIntire 2026-03-05 19:23:23 -06:00
parent 8bad7c724e
commit b0fcfb800f
No known key found for this signature in database

View file

@ -55,7 +55,20 @@ defmodule ToweropsWeb.Endpoint do
plug ToweropsWeb.Plugs.BruteForceProtection
plug ToweropsWeb.Plugs.SecurityHeaders
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
plug Plug.Telemetry,
event_prefix: [:phoenix, :endpoint],
log: :info,
metadata_filter: &__MODULE__.telemetry_metadata_filter/1
# Filter function for Plug.Telemetry - don't log health checks and uptime monitors
def telemetry_metadata_filter(metadata) do
case metadata do
%{conn: %{method: "GET", path_info: ["health"]}} -> false
%{conn: %{method: "GET", path_info: ["health", "time"]}} -> false
%{conn: %{method: "HEAD", path_info: []}} -> false
_ -> metadata
end
end
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],