2021-10-18 20:57:49 -07:00
|
|
|
/* eslint-disable import/no-cycle */
|
2021-12-23 13:29:04 -08:00
|
|
|
import { BinaryDataManager } from 'n8n-core';
|
2021-10-18 20:57:49 -07:00
|
|
|
import { IDataObject, IRun, TelemetryHelpers } from 'n8n-workflow';
|
|
|
|
import {
|
|
|
|
IDiagnosticInfo,
|
|
|
|
IInternalHooksClass,
|
|
|
|
IPersonalizationSurveyAnswers,
|
|
|
|
IWorkflowBase,
|
|
|
|
} from '.';
|
|
|
|
import { Telemetry } from './telemetry';
|
|
|
|
|
|
|
|
export class InternalHooksClass implements IInternalHooksClass {
|
2021-12-10 06:29:05 -08:00
|
|
|
private versionCli: string;
|
2021-10-18 20:57:49 -07:00
|
|
|
|
2021-12-10 06:29:05 -08:00
|
|
|
constructor(private telemetry: Telemetry, versionCli: string) {
|
|
|
|
this.versionCli = versionCli;
|
|
|
|
}
|
|
|
|
|
|
|
|
async onServerStarted(
|
|
|
|
diagnosticInfo: IDiagnosticInfo,
|
|
|
|
earliestWorkflowCreatedAt?: Date,
|
|
|
|
): Promise<unknown[]> {
|
2021-10-18 20:57:49 -07:00
|
|
|
const info = {
|
|
|
|
version_cli: diagnosticInfo.versionCli,
|
|
|
|
db_type: diagnosticInfo.databaseType,
|
|
|
|
n8n_version_notifications_enabled: diagnosticInfo.notificationsEnabled,
|
|
|
|
n8n_disable_production_main_process: diagnosticInfo.disableProductionWebhooksOnMainProcess,
|
|
|
|
n8n_basic_auth_active: diagnosticInfo.basicAuthActive,
|
|
|
|
system_info: diagnosticInfo.systemInfo,
|
|
|
|
execution_variables: diagnosticInfo.executionVariables,
|
|
|
|
n8n_deployment_type: diagnosticInfo.deploymentType,
|
2021-12-23 13:29:04 -08:00
|
|
|
n8n_binary_data_mode: diagnosticInfo.binaryDataMode,
|
2021-10-18 20:57:49 -07:00
|
|
|
};
|
2021-10-21 10:50:38 -07:00
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
this.telemetry.identify(info),
|
2021-12-10 06:29:05 -08:00
|
|
|
this.telemetry.track('Instance started', {
|
|
|
|
...info,
|
|
|
|
earliest_workflow_created: earliestWorkflowCreatedAt,
|
|
|
|
}),
|
2021-10-21 10:50:38 -07:00
|
|
|
]);
|
2021-10-18 20:57:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async onPersonalizationSurveySubmitted(answers: IPersonalizationSurveyAnswers): Promise<void> {
|
2021-10-21 10:50:38 -07:00
|
|
|
return this.telemetry.track('User responded to personalization questions', {
|
2021-10-18 20:57:49 -07:00
|
|
|
company_size: answers.companySize,
|
|
|
|
coding_skill: answers.codingSkill,
|
|
|
|
work_area: answers.workArea,
|
|
|
|
other_work_area: answers.otherWorkArea,
|
2021-12-10 09:53:31 -08:00
|
|
|
company_industry: answers.companyIndustry,
|
|
|
|
other_company_industry: answers.otherCompanyIndustry,
|
2021-10-18 20:57:49 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async onWorkflowCreated(workflow: IWorkflowBase): Promise<void> {
|
2021-12-10 06:29:05 -08:00
|
|
|
const { nodeGraph } = TelemetryHelpers.generateNodesGraph(workflow);
|
2021-10-21 10:50:38 -07:00
|
|
|
return this.telemetry.track('User created workflow', {
|
2021-10-18 20:57:49 -07:00
|
|
|
workflow_id: workflow.id,
|
2021-12-10 06:29:05 -08:00
|
|
|
node_graph: nodeGraph,
|
|
|
|
node_graph_string: JSON.stringify(nodeGraph),
|
2021-10-18 20:57:49 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async onWorkflowDeleted(workflowId: string): Promise<void> {
|
2021-10-21 10:50:38 -07:00
|
|
|
return this.telemetry.track('User deleted workflow', {
|
2021-10-18 20:57:49 -07:00
|
|
|
workflow_id: workflowId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async onWorkflowSaved(workflow: IWorkflowBase): Promise<void> {
|
2021-12-10 06:29:05 -08:00
|
|
|
const { nodeGraph } = TelemetryHelpers.generateNodesGraph(workflow);
|
|
|
|
|
2021-10-21 10:50:38 -07:00
|
|
|
return this.telemetry.track('User saved workflow', {
|
2021-10-18 20:57:49 -07:00
|
|
|
workflow_id: workflow.id,
|
2021-12-10 06:29:05 -08:00
|
|
|
node_graph: nodeGraph,
|
|
|
|
node_graph_string: JSON.stringify(nodeGraph),
|
|
|
|
version_cli: this.versionCli,
|
2021-10-18 20:57:49 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-23 13:29:04 -08:00
|
|
|
async onWorkflowPostExecute(
|
|
|
|
executionId: string,
|
|
|
|
workflow: IWorkflowBase,
|
|
|
|
runData?: IRun,
|
|
|
|
): Promise<void> {
|
2021-10-18 20:57:49 -07:00
|
|
|
const properties: IDataObject = {
|
|
|
|
workflow_id: workflow.id,
|
|
|
|
is_manual: false,
|
2021-12-10 06:29:05 -08:00
|
|
|
version_cli: this.versionCli,
|
2021-10-18 20:57:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (runData !== undefined) {
|
|
|
|
properties.execution_mode = runData.mode;
|
|
|
|
if (runData.mode === 'manual') {
|
|
|
|
properties.is_manual = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
properties.success = !!runData.finished;
|
|
|
|
|
|
|
|
if (!properties.success && runData?.data.resultData.error) {
|
|
|
|
properties.error_message = runData?.data.resultData.error.message;
|
|
|
|
let errorNodeName = runData?.data.resultData.error.node?.name;
|
|
|
|
properties.error_node_type = runData?.data.resultData.error.node?.type;
|
|
|
|
|
|
|
|
if (runData.data.resultData.lastNodeExecuted) {
|
|
|
|
const lastNode = TelemetryHelpers.getNodeTypeForName(
|
|
|
|
workflow,
|
|
|
|
runData.data.resultData.lastNodeExecuted,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (lastNode !== undefined) {
|
|
|
|
properties.error_node_type = lastNode.type;
|
|
|
|
errorNodeName = lastNode.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (properties.is_manual) {
|
|
|
|
const nodeGraphResult = TelemetryHelpers.generateNodesGraph(workflow);
|
|
|
|
properties.node_graph = nodeGraphResult.nodeGraph;
|
2021-12-10 06:29:05 -08:00
|
|
|
properties.node_graph_string = JSON.stringify(nodeGraphResult.nodeGraph);
|
|
|
|
|
2021-10-18 20:57:49 -07:00
|
|
|
if (errorNodeName) {
|
|
|
|
properties.error_node_id = nodeGraphResult.nameIndices[errorNodeName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 13:29:04 -08:00
|
|
|
return Promise.all([
|
|
|
|
BinaryDataManager.getInstance().persistBinaryDataForExecutionId(executionId),
|
|
|
|
this.telemetry.trackWorkflowExecution(properties),
|
|
|
|
]).then(() => {});
|
2021-10-18 20:57:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async onN8nStop(): Promise<void> {
|
2021-10-21 10:50:38 -07:00
|
|
|
const timeoutPromise = new Promise<void>((resolve) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
resolve();
|
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
|
|
|
|
return Promise.race([timeoutPromise, this.telemetry.trackN8nStop()]);
|
2021-10-18 20:57:49 -07:00
|
|
|
}
|
|
|
|
}
|