:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(logs): add the host mask rule to log pattern masking (#89009)
Jon McCallum1594387a9540
diff --git a/nodejs/src/logs/log-pattern-mask.test.ts b/nodejs/src/logs/log-pattern-mask.test.tsindex b722d000b149..4befdf50c5f1 100644--- a/nodejs/src/logs/log-pattern-mask.test.ts+++ b/nodejs/src/logs/log-pattern-mask.test.ts@@ -25,6 +25,15 @@ describe('log-pattern-mask', () => {['timestamp is not shredded by num', '2026-08-24T10:20:45Z', '<TIMESTAMP>'],['ip octets are not eaten by num', 'peer 192.168.0.1:8080 up', 'peer <IP>:<N> up'],['email starting with digits is not mangled by num', '[email protected] sent', '<EMAIL> sent'],+ ['email domain is not claimed by host', '[email protected] sent', '<EMAIL> sent'],+ ['hex-looking labels are claimed by host, not hex', 'from deadbeefdeadbeef.com now', 'from <HOST> now'],+ ['dotted quad stays an ip, not a host', 'from 10.0.0.1 now', 'from <IP> now'],+ ['host in a url masks whole', 'GET https://api.example.io/v2/users', 'GET https://<HOST>/v2/users'],+ [+ 'multi-label internal host masks whole',+ 'dial capture.posthog.svc.cluster.local failed',+ 'dial <HOST> failed',+ ],])('ordering: %s', (_name, input, expected) => {expect(maskString(input).masked).toEqual(expected)})@@ -38,9 +47,9 @@ describe('log-pattern-mask', () => {})it('counts fires per rule', () => {- const { ruleFires } = maskString('[email protected] [email protected] from 10.0.0.1 in 12ms')+ const { ruleFires } = maskString('[email protected] [email protected] via api.example.net from 10.0.0.1 in 12ms')const byName = Object.fromEntries(MASK_RULES.map((rule, i) => [rule.name, ruleFires[i]]))- expect(byName).toEqual({ timestamp: 0, uuid: 0, email: 2, hex0x: 0, hex: 0, ipv4: 1, num: 1 })+ expect(byName).toEqual({ timestamp: 0, uuid: 0, email: 2, host: 1, hex0x: 0, hex: 0, ipv4: 1, num: 1 })})})@@ -141,7 +150,7 @@ describe('log-pattern-mask', () => {.update(MASK_RULES.map((rule) => `${rule.name}\0${rule.pattern}\0${rule.replacement}`).join('\x01')).digest('hex').slice(0, 16)- expect({ version: PATTERN_VERSION, digest }).toEqual({ version: 1, digest: 'd8b059c25a24983d' })+ expect({ version: PATTERN_VERSION, digest }).toEqual({ version: 2, digest: 'cf5d13fd81dbf547' })})})diff --git a/nodejs/src/logs/log-pattern-mask.ts b/nodejs/src/logs/log-pattern-mask.tsindex 967115cf1fd5..0b4c6f7ca021 100644--- a/nodejs/src/logs/log-pattern-mask.ts+++ b/nodejs/src/logs/log-pattern-mask.ts@@ -2,9 +2,9 @@ import { createTrackedRE2 } from '~/common/utils/tracked-re2'import { parseLogBodyForIngestion } from './log-body-parse'-export const PATTERN_VERSION = 1+export const PATTERN_VERSION = 2-export type MaskRuleName = 'timestamp' | 'uuid' | 'email' | 'hex0x' | 'hex' | 'ipv4' | 'num'+export type MaskRuleName = 'timestamp' | 'uuid' | 'email' | 'host' | 'hex0x' | 'hex' | 'ipv4' | 'num'export type MaskRule = {name: MaskRuleName@@ -24,6 +24,12 @@ export const MASK_RULES: readonly MaskRule[] = [replacement: '<UUID>',},{ name: 'email', pattern: '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}', replacement: '<EMAIL>' },+ {+ name: 'host',+ pattern:+ '\\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.){1,8}(?:ai|app|aws|bot|cloud|co|com|de|dev|eu|fr|gg|internal|io|jp|local|me|net|nl|org|sh|so|tv|uk|us|xyz)\\b',+ replacement: '<HOST>',+ },{ name: 'hex0x', pattern: '\\b0x[0-9a-fA-F]+\\b', replacement: '<HEX>' },{ name: 'hex', pattern: '\\b[0-9a-fA-F]{16,}\\b', replacement: '<HEX>' },{ name: 'ipv4', pattern: '\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b', replacement: '<IP>' },