mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
chore: Anonymise ip addresses in rudderstack events (#11066)
This commit is contained in:
parent
835824cf53
commit
86c632aabf
|
@ -267,6 +267,44 @@ describe('Telemetry', () => {
|
|||
expect(execBuffer['2'].prod_success?.first).toEqual(execTime1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Rudderstack', () => {
|
||||
test("should call rudderStack.identify() with a fake IP address to instruct Rudderstack to not use the user's IP address", () => {
|
||||
const traits = {
|
||||
name: 'Test User',
|
||||
age: 30,
|
||||
isActive: true,
|
||||
};
|
||||
|
||||
telemetry.identify(traits);
|
||||
|
||||
const expectedArgs = {
|
||||
userId: instanceId,
|
||||
traits: { ...traits, instanceId },
|
||||
context: {
|
||||
ip: '0.0.0.0', // RudderStack anonymized IP
|
||||
},
|
||||
};
|
||||
|
||||
expect(mockRudderStack.identify).toHaveBeenCalledWith(expectedArgs);
|
||||
});
|
||||
|
||||
test("should call rudderStack.track() with a fake IP address to instruct Rudderstack to not use the user's IP address", () => {
|
||||
const eventName = 'Test Event';
|
||||
const properties = { user_id: '1234' };
|
||||
|
||||
telemetry.track(eventName, properties);
|
||||
|
||||
expect(mockRudderStack.track).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: eventName,
|
||||
context: {
|
||||
ip: '0.0.0.0', // RudderStack anonymized IP
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const fakeJestSystemTime = (dateTime: string | Date): Date => {
|
||||
|
|
|
@ -188,6 +188,10 @@ export class Telemetry {
|
|||
this.rudderStack.identify({
|
||||
userId: instanceId,
|
||||
traits: { ...traits, instanceId },
|
||||
context: {
|
||||
// provide a fake IP address to instruct RudderStack to not use the user's IP address
|
||||
ip: '0.0.0.0',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -212,13 +216,18 @@ export class Telemetry {
|
|||
userId: `${instanceId}${user_id ? `#${user_id}` : ''}`,
|
||||
event: eventName,
|
||||
properties: updatedProperties,
|
||||
context: {},
|
||||
};
|
||||
|
||||
if (withPostHog) {
|
||||
this.postHog?.track(payload);
|
||||
}
|
||||
|
||||
return this.rudderStack.track(payload);
|
||||
return this.rudderStack.track({
|
||||
...payload,
|
||||
// provide a fake IP address to instruct RudderStack to not use the user's IP address
|
||||
context: { ...payload.context, ip: '0.0.0.0' },
|
||||
});
|
||||
}
|
||||
|
||||
// test helpers
|
||||
|
|
|
@ -38,9 +38,11 @@ describe('telemetry', () => {
|
|||
|
||||
telemetry.identify(userId, instanceId);
|
||||
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||
instance_id: instanceId,
|
||||
});
|
||||
expect(identifyFunction).toHaveBeenCalledWith(
|
||||
`${instanceId}#${userId}`,
|
||||
{ instance_id: instanceId },
|
||||
{ context: { ip: '0.0.0.0' } },
|
||||
);
|
||||
});
|
||||
|
||||
it('Rudderstack identify method should be called when proving userId and versionCli ', () => {
|
||||
|
@ -60,10 +62,14 @@ describe('telemetry', () => {
|
|||
|
||||
telemetry.identify(userId, instanceId, versionCli);
|
||||
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
});
|
||||
expect(identifyFunction).toHaveBeenCalledWith(
|
||||
`${instanceId}#${userId}`,
|
||||
{
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
},
|
||||
{ context: { ip: '0.0.0.0' } },
|
||||
);
|
||||
});
|
||||
|
||||
it('Rudderstack identify method should be called when proving userId and versionCli and projectId', () => {
|
||||
|
@ -84,10 +90,14 @@ describe('telemetry', () => {
|
|||
|
||||
telemetry.identify(userId, instanceId, versionCli, projectId);
|
||||
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}#${projectId}`, {
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
});
|
||||
expect(identifyFunction).toHaveBeenCalledWith(
|
||||
`${instanceId}#${userId}#${projectId}`,
|
||||
{
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
},
|
||||
{ context: { ip: '0.0.0.0' } },
|
||||
);
|
||||
});
|
||||
|
||||
it('Rudderstack identify method should be called when proving userId and deployment type is cloud ', () => {
|
||||
|
@ -111,11 +121,15 @@ describe('telemetry', () => {
|
|||
|
||||
telemetry.identify(userId, instanceId, versionCli);
|
||||
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
user_cloud_id: userCloudId,
|
||||
});
|
||||
expect(identifyFunction).toHaveBeenCalledWith(
|
||||
`${instanceId}#${userId}`,
|
||||
{
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
user_cloud_id: userCloudId,
|
||||
},
|
||||
{ context: { ip: '0.0.0.0' } },
|
||||
);
|
||||
});
|
||||
|
||||
it('Rudderstack identify method should be called when proving userId and deployment type is cloud', () => {
|
||||
|
@ -139,11 +153,15 @@ describe('telemetry', () => {
|
|||
|
||||
telemetry.identify(userId, instanceId, versionCli);
|
||||
expect(identifyFunction).toHaveBeenCalledTimes(1);
|
||||
expect(identifyFunction).toHaveBeenCalledWith(`${instanceId}#${userId}`, {
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
user_cloud_id: userCloudId,
|
||||
});
|
||||
expect(identifyFunction).toHaveBeenCalledWith(
|
||||
`${instanceId}#${userId}`,
|
||||
{
|
||||
instance_id: instanceId,
|
||||
version_cli: versionCli,
|
||||
user_cloud_id: userCloudId,
|
||||
},
|
||||
{ context: { ip: '0.0.0.0' } },
|
||||
);
|
||||
});
|
||||
|
||||
it('Rudderstack reset method should be called when proving userId and deployment type is cloud', () => {
|
||||
|
@ -175,10 +193,14 @@ describe('telemetry', () => {
|
|||
telemetry.track(event, properties, options);
|
||||
|
||||
expect(trackFunction).toHaveBeenCalledTimes(1);
|
||||
expect(trackFunction).toHaveBeenCalledWith(event, {
|
||||
...properties,
|
||||
version_cli: MOCK_VERSION_CLI,
|
||||
});
|
||||
expect(trackFunction).toHaveBeenCalledWith(
|
||||
event,
|
||||
{
|
||||
...properties,
|
||||
version_cli: MOCK_VERSION_CLI,
|
||||
},
|
||||
{ context: { ip: '0.0.0.0' } },
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -94,6 +94,12 @@ export class Telemetry {
|
|||
this.rudderStack?.identify(
|
||||
`${instanceId}#${userId}${projectId ? '#' + projectId : ''}`,
|
||||
traits,
|
||||
{
|
||||
context: {
|
||||
// provide a fake IP address to instruct RudderStack to not use the user's IP address
|
||||
ip: '0.0.0.0',
|
||||
},
|
||||
},
|
||||
);
|
||||
} else {
|
||||
this.rudderStack?.reset();
|
||||
|
@ -112,7 +118,12 @@ export class Telemetry {
|
|||
version_cli: useRootStore().versionCli,
|
||||
};
|
||||
|
||||
this.rudderStack.track(event, updatedProperties);
|
||||
this.rudderStack.track(event, updatedProperties, {
|
||||
context: {
|
||||
// provide a fake IP address to instruct RudderStack to not use the user's IP address
|
||||
ip: '0.0.0.0',
|
||||
},
|
||||
});
|
||||
|
||||
if (options.withPostHog) {
|
||||
usePostHog().capture(event, updatedProperties);
|
||||
|
@ -136,7 +147,12 @@ export class Telemetry {
|
|||
properties.theme = useUIStore().appliedTheme;
|
||||
|
||||
const category = route.meta?.telemetry?.pageCategory || 'Editor';
|
||||
this.rudderStack.page(category, pageName, properties);
|
||||
this.rudderStack.page(category, pageName, properties, {
|
||||
context: {
|
||||
// provide a fake IP address to instruct RudderStack to not use the user's IP address
|
||||
ip: '0.0.0.0',
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.pageEventQueue.push({
|
||||
route,
|
||||
|
|
Loading…
Reference in a new issue