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:
Filipe Tavares
2026-07-10 14:58:32 +01:00
committed by GitHub
parent ff5d4f1d3e
commit 8028fb0634
3 changed files with 29 additions and 2 deletions
+7 -1
View File
@@ -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' };
+7 -1
View File
@@ -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)