-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cdp): add ip anon transformation #28377
feat(cdp): add ip anon transformation #28377
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Added IP anonymization transformation to replace the last octet of IPv4 addresses with zero, enhancing user privacy in PostHog's CDP functionality.
- Added
ip-anonymization.template.ts
with string splitting for efficient IPv4 anonymization (e.g., 192.168.1.1 → 192.168.1.0) - Implemented comprehensive test suite in
ip-anonymization.template.test.ts
covering valid/invalid IPs and edge cases - Integrated template into
HOG_FUNCTION_TEMPLATES_TRANSFORMATIONS
array inindex.ts
- Template marked as 'alpha' status with clear description and free availability
- Missing IPv6 support and potential edge case handling for malformed IP strings
3 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile
} | ||
|
||
let ip := event.properties.$ip | ||
let parts := splitByString('.', ip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: No validation of IP address octets. Values like '999.999.999.999' or 'a.b.c.d' will be processed as valid IPs if they contain 4 parts.
let parts := splitByString('.', ip) | |
let parts := splitByString('.', ip) | |
// Validate each octet is a number between 0-255 | |
if (length(parts) = 4 and all(x -> toInt(x) >= 0 and toInt(x) <= 255, parts)) { |
...server/src/cdp/templates/_transformations/ip-anonymization/ip-anonymization.template.test.ts
Show resolved
Hide resolved
let ip := event.properties.$ip | ||
let parts := splitByString('.', ip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider trimming the IP string to handle whitespace in input
...server/src/cdp/templates/_transformations/ip-anonymization/ip-anonymization.template.test.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good with a small comment
plugin-server/src/cdp/templates/_transformations/ip-anonymization/ip-anonymization.template.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually really like the bots suggestions but approved as its not blocking
…ion/ip-anonymization.template.test.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Problem
We want to offer the same (or better) transformations as competitors.
IP anonymization transformation but uses string splitting instead of regex for performance.
Changes
👉 Stay up-to-date with PostHog coding conventions for a smoother review.
Does this work well for both Cloud and self-hosted?
How did you test this code?