refactor(core): Add node ID to log streaming events (#16313)

This commit is contained in:
Iván Ovejero
2025-06-13 13:08:16 +02:00
committed by GitHub
parent 43c52a8b4f
commit ce3c92abe2
8 changed files with 67 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ export interface EventPayloadNode extends AbstractEventPayload {
msg?: string;
executionId: string;
nodeName: string;
nodeId?: string;
workflowId?: string;
workflowName: string;
nodeType?: string;

View File

@@ -561,6 +561,8 @@ describe('LogStreamingEventRelay', () => {
executionId: 'exec456',
nodeName: 'HTTP Request',
workflow,
nodeId: 'node2',
nodeType: 'n8n-nodes-base.httpRequest',
};
eventService.emit('node-pre-execute', event);
@@ -573,6 +575,7 @@ describe('LogStreamingEventRelay', () => {
workflowId: 'wf303',
workflowName: 'Test Workflow with Nodes',
nodeType: 'n8n-nodes-base.httpRequest',
nodeId: 'node2',
},
});
});
@@ -606,6 +609,8 @@ describe('LogStreamingEventRelay', () => {
executionId: 'exec789',
nodeName: 'HTTP Response',
workflow,
nodeId: 'node2',
nodeType: 'n8n-nodes-base.httpResponse',
};
eventService.emit('node-post-execute', event);
@@ -618,6 +623,7 @@ describe('LogStreamingEventRelay', () => {
workflowId: 'wf404',
workflowName: 'Test Workflow with Completed Node',
nodeType: 'n8n-nodes-base.httpResponse',
nodeId: 'node2',
},
});
});

View File

@@ -111,13 +111,17 @@ export type RelayEventMap = {
'node-pre-execute': {
executionId: string;
workflow: IWorkflowBase;
nodeId?: string;
nodeName: string;
nodeType?: string;
};
'node-post-execute': {
executionId: string;
workflow: IWorkflowBase;
nodeId?: string;
nodeName: string;
nodeType?: string;
};
// #endregion

View File

@@ -180,28 +180,42 @@ export class LogStreamingEventRelay extends EventRelay {
// #region Node
private nodePreExecute({ workflow, executionId, nodeName }: RelayEventMap['node-pre-execute']) {
private nodePreExecute({
workflow,
executionId,
nodeId,
nodeName,
nodeType,
}: RelayEventMap['node-pre-execute']) {
void this.eventBus.sendNodeEvent({
eventName: 'n8n.node.started',
payload: {
workflowId: workflow.id,
workflowName: workflow.name,
executionId,
nodeType: workflow.nodes.find((n) => n.name === nodeName)?.type,
nodeType,
nodeName,
nodeId,
},
});
}
private nodePostExecute({ workflow, executionId, nodeName }: RelayEventMap['node-post-execute']) {
private nodePostExecute({
workflow,
executionId,
nodeType,
nodeName,
nodeId,
}: RelayEventMap['node-post-execute']) {
void this.eventBus.sendNodeEvent({
eventName: 'n8n.node.finished',
payload: {
workflowId: workflow.id,
workflowName: workflow.name,
executionId,
nodeType: workflow.nodes.find((n) => n.name === nodeName)?.type,
nodeType,
nodeName,
nodeId,
},
});
}

View File

@@ -54,6 +54,8 @@ describe('Execution Lifecycle Hooks', () => {
const workflowExecutionService = mockInstance(WorkflowExecutionService);
const nodeName = 'Test Node';
const nodeType = 'n8n-nodes-base.testNode';
const nodeId = 'test-node-id';
const node = mock<INode>();
const workflowId = 'test-workflow-id';
const executionId = 'test-execution-id';
@@ -63,7 +65,16 @@ describe('Execution Lifecycle Hooks', () => {
active: true,
isArchived: false,
connections: {},
nodes: [],
nodes: [
{
id: nodeId,
name: nodeName,
type: nodeType,
typeVersion: 1,
position: [100, 200],
parameters: {},
},
],
settings: {},
createdAt: new Date(),
updatedAt: new Date(),
@@ -155,6 +166,8 @@ describe('Execution Lifecycle Hooks', () => {
executionId,
workflow: workflowData,
nodeName,
nodeType,
nodeId,
});
});
});
@@ -167,6 +180,8 @@ describe('Execution Lifecycle Hooks', () => {
executionId,
workflow: workflowData,
nodeName,
nodeType,
nodeId,
});
});
});

View File

@@ -52,11 +52,27 @@ function hookFunctionsNodeEvents(hooks: ExecutionLifecycleHooks) {
const eventService = Container.get(EventService);
hooks.addHandler('nodeExecuteBefore', function (nodeName) {
const { executionId, workflowData: workflow } = this;
eventService.emit('node-pre-execute', { executionId, workflow, nodeName });
const node = workflow.nodes.find((n) => n.name === nodeName);
eventService.emit('node-pre-execute', {
executionId,
workflow,
nodeId: node?.id,
nodeName,
nodeType: node?.type,
});
});
hooks.addHandler('nodeExecuteAfter', function (nodeName) {
const { executionId, workflowData: workflow } = this;
eventService.emit('node-post-execute', { executionId, workflow, nodeName });
const node = workflow.nodes.find((n) => n.name === nodeName);
eventService.emit('node-post-execute', {
executionId,
workflow,
nodeId: node?.id,
nodeName,
nodeType: node?.type,
});
});
}

View File

@@ -323,6 +323,7 @@ describe('ExecutionRecoveryService', () => {
workflowName: workflow.name,
nodeName: 'DebugHelper',
nodeType: 'n8n-nodes-base.debugHelper',
nodeId: '123',
},
}),
);

View File

@@ -15,6 +15,7 @@ export const setupMessages = (executionId: string, workflowName: string): EventM
workflowName,
nodeName: 'When clicking "Execute workflow"',
nodeType: 'n8n-nodes-base.manualTrigger',
nodeId: '123',
},
}),
new EventMessageNode({
@@ -24,6 +25,7 @@ export const setupMessages = (executionId: string, workflowName: string): EventM
workflowName,
nodeName: 'When clicking "Execute workflow"',
nodeType: 'n8n-nodes-base.manualTrigger',
nodeId: '123',
},
}),
new EventMessageNode({
@@ -33,6 +35,7 @@ export const setupMessages = (executionId: string, workflowName: string): EventM
workflowName,
nodeName: 'DebugHelper',
nodeType: 'n8n-nodes-base.debugHelper',
nodeId: '123',
},
}),
];