diff --git a/apitally/client/request_logging.py b/apitally/client/request_logging.py index 6ef28dd..575a29a 100644 --- a/apitally/client/request_logging.py +++ b/apitally/client/request_logging.py @@ -5,7 +5,6 @@ import threading import time from collections import deque -from contextlib import suppress from dataclasses import dataclass, field from functools import lru_cache from io import BufferedReader @@ -29,14 +28,14 @@ ALLOWED_CONTENT_TYPES = ["application/json", "text/plain"] EXCLUDE_PATH_PATTERNS = [ r"/_?healthz?$", - r"/_?health[_-]?checks?$", - r"/_?heart[_-]?beats?$", + r"/_?health[\-_]?checks?$", + r"/_?heart[\-_]?beats?$", r"/ping$", r"/ready$", r"/live$", ] EXCLUDE_USER_AGENT_PATTERNS = [ - r"health[_- ]?check", + r"health[\-_ ]?check", r"microsoft-azure-application-lb", r"googlehc", r"kube-probe", @@ -307,9 +306,8 @@ def _should_mask_header(self, header_name: str) -> bool: @staticmethod def _match_patterns(value: str, patterns: List[str]) -> bool: for pattern in patterns: - with suppress(re.error): - if re.search(pattern, value, re.I) is not None: - return True + if re.search(pattern, value, re.I) is not None: + return True return False @staticmethod diff --git a/tests/test_client_request_logging.py b/tests/test_client_request_logging.py index d254bb8..ddccb49 100644 --- a/tests/test_client_request_logging.py +++ b/tests/test_client_request_logging.py @@ -121,8 +121,8 @@ def test_request_log_exclusion(request_logger: RequestLogger, request_dict: Requ response_dict["status_code"] = 404 request_logger.log_request(request_dict, response_dict) assert len(request_logger.write_deque) == 1 - response_dict["status_code"] = 200 + response_dict["status_code"] = 200 request_dict["path"] = "/api/excluded" request_logger.log_request(request_dict, response_dict) assert len(request_logger.write_deque) == 1 @@ -131,6 +131,11 @@ def test_request_log_exclusion(request_logger: RequestLogger, request_dict: Requ request_logger.log_request(request_dict, response_dict) assert len(request_logger.write_deque) == 1 + request_dict["path"] = "/" + request_dict["headers"] = [("User-Agent", "ELB-HealthChecker/2.0")] + request_logger.log_request(request_dict, response_dict) + assert len(request_logger.write_deque) == 1 + def test_request_log_masking(request_logger: RequestLogger, request_dict: RequestDict, response_dict: ResponseDict): from apitally.client.request_logging import BODY_MASKED, MASKED