mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core): Workflow Execution Statistics (#4200)
Add recording and reporting of workflow execution statistics
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import RudderStack from '@rudderstack/rudder-sdk-node';
|
||||
import PostHog from 'posthog-node';
|
||||
import { PostHog } from 'posthog-node';
|
||||
import { ITelemetryTrackProperties, LoggerProxy } from 'n8n-workflow';
|
||||
import config from '@/config';
|
||||
import { IExecutionTrackProperties } from '@/Interfaces';
|
||||
@@ -20,6 +20,7 @@ interface IExecutionsBuffer {
|
||||
manual_success?: IExecutionTrackData;
|
||||
prod_error?: IExecutionTrackData;
|
||||
prod_success?: IExecutionTrackData;
|
||||
user_id: string | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -80,11 +81,15 @@ export class Telemetry {
|
||||
}
|
||||
|
||||
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],
|
||||
});
|
||||
const promise = this.track(
|
||||
'Workflow execution count',
|
||||
{
|
||||
event_version: '2',
|
||||
workflow_id: workflowId,
|
||||
...this.executionCountsBuffer[workflowId],
|
||||
},
|
||||
{ withPostHog: true },
|
||||
);
|
||||
|
||||
return promise;
|
||||
});
|
||||
@@ -99,7 +104,9 @@ export class Telemetry {
|
||||
const execTime = new Date();
|
||||
const workflowId = properties.workflow_id;
|
||||
|
||||
this.executionCountsBuffer[workflowId] = this.executionCountsBuffer[workflowId] ?? {};
|
||||
this.executionCountsBuffer[workflowId] = this.executionCountsBuffer[workflowId] ?? {
|
||||
user_id: properties.user_id,
|
||||
};
|
||||
|
||||
const key: ExecutionTrackDataKey = `${properties.is_manual ? 'manual' : 'prod'}_${
|
||||
properties.success ? 'success' : 'error'
|
||||
@@ -184,6 +191,7 @@ export class Telemetry {
|
||||
return Promise.all([
|
||||
this.postHog.capture({
|
||||
distinctId: payload.userId,
|
||||
sendFeatureFlags: true,
|
||||
...payload,
|
||||
}),
|
||||
this.rudderStack.track(payload),
|
||||
@@ -200,7 +208,7 @@ export class Telemetry {
|
||||
async isFeatureFlagEnabled(
|
||||
featureFlagName: string,
|
||||
{ user_id: userId }: ITelemetryTrackProperties = {},
|
||||
): Promise<boolean> {
|
||||
): Promise<boolean | undefined> {
|
||||
if (!this.postHog) return Promise.resolve(false);
|
||||
|
||||
const fullId = [this.instanceId, userId].join('#');
|
||||
|
||||
Reference in New Issue
Block a user