Skip to content

Commit 4a95396

Browse files
committed
Exclude requests from health checkers based on User-Agent
1 parent d3c3ac4 commit 4a95396

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/common/requestLogger.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const EXCLUDE_PATH_PATTERNS = [
2323
/\/ready$/i,
2424
/\/live$/i,
2525
];
26+
const EXCLUDE_USER_AGENT_PATTERNS = [
27+
/health[-_ ]?check/i,
28+
/microsoft-azure-application-lb/i,
29+
/googlehc/i,
30+
/kube-probe/i,
31+
];
2632
const MASK_QUERY_PARAM_PATTERNS = [
2733
/auth/i,
2834
/api-?key/i,
@@ -113,6 +119,12 @@ export default class RequestLogger {
113119
return matchPatterns(urlPath, patterns);
114120
}
115121

122+
private shouldExcludeUserAgent(userAgent?: string) {
123+
return userAgent
124+
? matchPatterns(userAgent, EXCLUDE_USER_AGENT_PATTERNS)
125+
: false;
126+
}
127+
116128
private shouldMaskQueryParam(name: string) {
117129
const patterns = [
118130
...this.config.maskQueryParams,
@@ -155,9 +167,13 @@ export default class RequestLogger {
155167

156168
const url = new URL(request.url);
157169
const path = request.path ?? url.pathname;
170+
const userAgent = request.headers.find(
171+
([k]) => k.toLowerCase() === "user-agent",
172+
)?.[1];
158173

159174
if (
160175
this.shouldExcludePath(path) ||
176+
this.shouldExcludeUserAgent(userAgent) ||
161177
(this.config.excludeCallback?.(request, response) ?? false)
162178
) {
163179
return;

0 commit comments

Comments
 (0)