Filter out curl healthchecks from access logs

This commit is contained in:
Antti Kettunen 2026-04-21 18:13:48 +03:00
parent 71e114b6fe
commit bf31e929b5
No known key found for this signature in database
GPG key ID: C6B2A3D250359BD7

View file

@ -35,6 +35,10 @@ class FilteredGunicornLogger(GunicornLogger):
".eot",
)
_HEALTHCHECK_USER_AGENTS = (
"curl/",
)
def _should_skip_access_log(self, environ) -> bool:
path = environ.get("PATH_INFO") or ""
if not path:
@ -49,6 +53,11 @@ class FilteredGunicornLogger(GunicornLogger):
):
return True
if lower_path == "/":
user_agent = (environ.get("HTTP_USER_AGENT") or "").lower()
if any(token in user_agent for token in self._HEALTHCHECK_USER_AGENTS):
return True
return any(lower_path.endswith(suffix) for suffix in self._STATIC_SUFFIXES)
def access(self, resp, req, environ, request_time):