mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-01 15:47:41 +08:00
feat(core): Send user cloud id on backend telemetry events (no-changelog) (#33923)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import { isApiEnabled, loadPublicApiVersions } from '@/public-api';
|
||||
import { Push } from '@/push';
|
||||
import * as ResponseHelper from '@/response-helper';
|
||||
import type { FrontendService } from '@/services/frontend.service';
|
||||
import { Telemetry } from '@/telemetry';
|
||||
|
||||
import '@/controllers/active-workflows.controller';
|
||||
import '@/controllers/annotation-tags.controller.ee';
|
||||
@@ -168,7 +169,12 @@ export class Server extends AbstractServer {
|
||||
|
||||
const { frontendService } = this;
|
||||
if (frontendService) {
|
||||
await this.externalHooks.run('frontend.settings', [await frontendService.getSettings()]);
|
||||
const frontendSettings = await frontendService.getSettings();
|
||||
await this.externalHooks.run('frontend.settings', [frontendSettings]);
|
||||
|
||||
if (this.globalConfig.deployment.type === 'cloud') {
|
||||
Container.get(Telemetry).setUserCloudId(frontendSettings.n8nMetadata?.userId);
|
||||
}
|
||||
}
|
||||
|
||||
await this.postHogClient.init();
|
||||
|
||||
@@ -999,6 +999,21 @@ describe('Telemetry', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('should call rudderStack.track() with the user_cloud_id context trait when set', () => {
|
||||
telemetry.setUserCloudId('cloud-user-123');
|
||||
|
||||
telemetry.track('Test Event', { user_id: '1234' });
|
||||
|
||||
expect(mockRudderStack.track).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
context: {
|
||||
ip: '0.0.0.0',
|
||||
traits: { user_cloud_id: 'cloud-user-123' },
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should include instance_id, version_cli, and user_id in track properties', () => {
|
||||
const eventName = 'Test Event';
|
||||
const properties = { user_id: '1234', custom_prop: 'value' };
|
||||
|
||||
@@ -99,6 +99,8 @@ interface IAgentSessionMetricsBuffer {
|
||||
export class Telemetry {
|
||||
private rudderStack?: RudderStack;
|
||||
|
||||
private userCloudId?: string;
|
||||
|
||||
private pulseIntervalReference: NodeJS.Timeout;
|
||||
|
||||
private executionCountsBuffer: IExecutionsBuffer = {};
|
||||
@@ -549,6 +551,10 @@ export class Telemetry {
|
||||
}
|
||||
}
|
||||
|
||||
setUserCloudId(userCloudId?: string) {
|
||||
this.userCloudId = userCloudId;
|
||||
}
|
||||
|
||||
track(eventName: string, properties: ITelemetryTrackProperties = {}) {
|
||||
if (!this.rudderStack) {
|
||||
return;
|
||||
@@ -567,7 +573,7 @@ export class Telemetry {
|
||||
userId: `${instanceId}${user_id ? `#${user_id}` : ''}`,
|
||||
event: eventName,
|
||||
properties: updatedProperties,
|
||||
context: {},
|
||||
context: this.userCloudId ? { traits: { user_cloud_id: this.userCloudId } } : {},
|
||||
};
|
||||
|
||||
// Build the actual payload that will be sent to RudderStack (with fake IP)
|
||||
|
||||
Reference in New Issue
Block a user