-
Notifications
You must be signed in to change notification settings - Fork 207
fix: apply before_send to identify and groupIdentify events #2550
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
base: main
Are you sure you want to change the base?
fix: apply before_send to identify and groupIdentify events #2550
Conversation
|
@MohamedH1998 is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize it. |
| $set_once: userPropsOnce, | ||
| }, | ||
| { disableGeoip } | ||
| this.addPendingPromise( |
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.
this is consistent w/ capture method implementation
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.
2 files reviewed, 1 comment
packages/node/src/client.ts
Outdated
| this.prepareEventMessage({ | ||
| distinctId: distinctId || `$${groupType}_${groupKey}`, | ||
| event: '$groupidentify', | ||
| properties: { | ||
| $group_type: groupType, | ||
| $group_key: groupKey, | ||
| $group_set: properties || {}, | ||
| }, | ||
| disableGeoip, | ||
| }) | ||
| .then(({ distinctId, properties, options }) => { | ||
| const { $group_type, $group_key, $group_set, ...eventProperties } = properties | ||
| return super.groupIdentifyStateless( | ||
| $group_type as string, | ||
| $group_key as string | number, | ||
| $group_set as PostHogEventProperties, | ||
| options, | ||
| distinctId, | ||
| eventProperties | ||
| ) | ||
| }) | ||
| .catch((err) => { | ||
| if (err) { | ||
| console.error(err) | ||
| } | ||
| }) |
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: missing addPendingPromise() wrapper around promise chain
both identify() (line 437) and identifyImmediate() (line 483) wrap their promise chains with addPendingPromise(), but groupIdentify() doesn't. this means the promise won't be tracked in the promise queue, potentially causing events to be lost during flush() operations.
wrap the entire promise chain with this.addPendingPromise(...) like the other methods do.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/node/src/client.ts
Line: 1148:1173
Comment:
**logic:** missing `addPendingPromise()` wrapper around promise chain
both `identify()` (line 437) and `identifyImmediate()` (line 483) wrap their promise chains with `addPendingPromise()`, but `groupIdentify()` doesn't. this means the promise won't be tracked in the promise queue, potentially causing events to be lost during `flush()` operations.
wrap the entire promise chain with `this.addPendingPromise(...)` like the other methods do.
How can I resolve this? If you propose a fix, please make it concise.
packages/node/src/client.ts
Outdated
| groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }: GroupIdentifyMessage): void { | ||
| super.groupIdentifyStateless(groupType, groupKey, properties, { disableGeoip }, distinctId) | ||
| this.prepareEventMessage({ | ||
| distinctId: distinctId || `$${groupType}_${groupKey}`, |
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.
this is how groupIdentifyStateless also sets distinctId when the incoming param is null
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
|
hey @MohamedH1998 i'm not familiar with the node SDK 🙈 i'll find out who is best to review - thanks for the PR! can you expand on the things you want to edit in the identify event? |
|
the main aim of this change is to give the identify methods access to the before_send hook, so users can redact data before events are sent the changes to the identify methods (
cc: @pauldambra |
|
thanks @MohamedH1998, makes sense in posthog-js (the browser SDK) we do let folk amend any event we have seen a few instances where they redact themselves into a bad state, but that's i guess a consequence of this kind of power_user escape hatch 😊 |
|
yeahh exactly, appreciate the comments @pauldambra |
| jest.runOnlyPendingTimers() | ||
| await waitForPromises() | ||
|
|
||
| await waitForFlushTimer() |
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'd be interested to see what refactor an AI tool would make of this if we asked it to parameterise the tests
there's a lot of repetition (normally i wouldn't ask on an external PR, but since I'm assuming something like Claude would do the work for you 🙈 )
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.
yep, let's try an AI pass to tighten up this test file and then i think we're good to go
(you're welcome to do that by hand obvs but 🤖 is a good calculator for words)
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.
done, shout out claude code 🫡
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.
any chance of a second glance at this @pauldambra
hpouillot
left a comment
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.
LGTM
Problem
An issue was raised where the
before_sendcallback was only invoked forcaptureevents, but not foridentifyorgroupIdentifyevents. This meant that users were unable to modify these event types viabefore_send.Changes
identify()andidentifyImmediate()methods to useprepareEventMessage()groupIdentify()to useprepareEventMessage()before_sendfunctionality for the updated methodsRelease info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file