diff --git a/packages/cli/src/telemetry/index.ts b/packages/cli/src/telemetry/index.ts index 7edb6f6172..f278bac24f 100644 --- a/packages/cli/src/telemetry/index.ts +++ b/packages/cli/src/telemetry/index.ts @@ -79,19 +79,29 @@ export class Telemetry { return; } - const allPromises = Object.keys(this.executionCountsBuffer).map(async (workflowId) => { - const promise = this.track( - 'Workflow execution count', - { - event_version: '2', - workflow_id: workflowId, - ...this.executionCountsBuffer[workflowId], - }, - { withPostHog: true }, - ); + const allPromises = Object.keys(this.executionCountsBuffer) + .filter((workflowId) => { + const data = this.executionCountsBuffer[workflowId]; + const sum = + (data.manual_error?.count ?? 0) + + (data.manual_success?.count ?? 0) + + (data.prod_error?.count ?? 0) + + (data.prod_success?.count ?? 0); + return sum > 0; + }) + .map(async (workflowId) => { + const promise = this.track( + 'Workflow execution count', + { + event_version: '2', + workflow_id: workflowId, + ...this.executionCountsBuffer[workflowId], + }, + { withPostHog: true }, + ); - return promise; - }); + return promise; + }); this.executionCountsBuffer = {}; @@ -128,7 +138,11 @@ export class Telemetry { this.executionCountsBuffer[workflowId][key]!.count++; } - if (!properties.success && properties.error_node_type?.startsWith('n8n-nodes-base')) { + if ( + !properties.success && + properties.is_manual && + properties.error_node_type?.startsWith('n8n-nodes-base') + ) { void this.track('Workflow execution errored', properties); } } diff --git a/packages/cli/test/unit/Telemetry.test.ts b/packages/cli/test/unit/Telemetry.test.ts index 988571e51b..4df728add1 100644 --- a/packages/cli/test/unit/Telemetry.test.ts +++ b/packages/cli/test/unit/Telemetry.test.ts @@ -211,7 +211,6 @@ describe('Telemetry', () => { await telemetry.trackWorkflowExecution(payload); expect(spyTrack).toHaveBeenCalledTimes(0); - execBuffer = telemetry.getCountsBuffer(); expect(execBuffer['1'].manual_error).toBeUndefined(); @@ -254,19 +253,20 @@ describe('Telemetry', () => { // failed execution n8n node payload.success = false; payload.error_node_type = 'n8n-nodes-base.merge'; + payload.is_manual = true; await telemetry.trackWorkflowExecution(payload); expect(spyTrack).toHaveBeenCalledTimes(1); execBuffer = telemetry.getCountsBuffer(); - expect(execBuffer['1'].manual_error).toBeUndefined(); + expect(execBuffer['1'].manual_error?.count).toBe(1); expect(execBuffer['1'].manual_success).toBeUndefined(); expect(execBuffer['2'].manual_error).toBeUndefined(); expect(execBuffer['2'].manual_success).toBeUndefined(); expect(execBuffer['2'].prod_error).toBeUndefined(); expect(execBuffer['1'].prod_success?.count).toBe(2); - expect(execBuffer['1'].prod_error?.count).toBe(2); + expect(execBuffer['1'].prod_error?.count).toBe(1); expect(execBuffer['2'].prod_success?.count).toBe(2); expect(execBuffer['1'].prod_error?.first).toEqual(execTime2);