From 792b1c1ffb0eb279bc3451787891ca3835f59d9f Mon Sep 17 00:00:00 2001 From: Michael Auerswald Date: Tue, 30 May 2023 17:59:55 +0200 Subject: [PATCH] feat(core): Add metadata (customdata) to event log (#6334) * add metadata (customdata) to event log * lint fix * use reduce --- packages/cli/src/InternalHooks.ts | 14 ++++++++++++++ packages/cli/src/WorkflowRunner.ts | 1 + .../MessageEventBusDestinationWebhook.ee.ts | 6 +++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/InternalHooks.ts b/packages/cli/src/InternalHooks.ts index 55793c0528..4656658c1d 100644 --- a/packages/cli/src/InternalHooks.ts +++ b/packages/cli/src/InternalHooks.ts @@ -31,6 +31,7 @@ import type { User } from '@db/entities/User'; import { N8N_VERSION } from '@/constants'; import * as Db from '@/Db'; import { NodeTypes } from './NodeTypes'; +import type { ExecutionMetadata } from './databases/entities/ExecutionMetadata'; function userToPayload(user: User): { userId: string; @@ -253,7 +254,17 @@ export class InternalHooks implements IInternalHooksClass { executionId: string, executionMode: WorkflowExecuteMode, workflowData?: IWorkflowBase, + executionMetadata?: ExecutionMetadata[], ): Promise { + let metaData; + try { + if (executionMetadata) { + metaData = executionMetadata.reduce((acc, meta) => { + return { ...acc, [meta.key]: meta.value }; + }, {}); + } + } catch {} + void Promise.all([ eventBus.sendWorkflowEvent({ eventName: 'n8n.workflow.crashed', @@ -262,6 +273,7 @@ export class InternalHooks implements IInternalHooksClass { isManual: executionMode === 'manual', workflowId: workflowData?.id?.toString(), workflowName: workflowData?.name, + metaData, }, }), ]); @@ -430,6 +442,7 @@ export class InternalHooks implements IInternalHooksClass { workflowId: properties.workflow_id, isManual: properties.is_manual, workflowName: workflow.name, + metaData: runData?.data?.resultData?.metadata, }, }) : eventBus.sendWorkflowEvent({ @@ -445,6 +458,7 @@ export class InternalHooks implements IInternalHooksClass { errorMessage: properties.error_message?.toString(), isManual: properties.is_manual, workflowName: workflow.name, + metaData: runData?.data?.resultData?.metadata, }, }), ); diff --git a/packages/cli/src/WorkflowRunner.ts b/packages/cli/src/WorkflowRunner.ts index 58390f4959..c2ea34e908 100644 --- a/packages/cli/src/WorkflowRunner.ts +++ b/packages/cli/src/WorkflowRunner.ts @@ -133,6 +133,7 @@ export class WorkflowRunner { executionId, executionMode, executionFlattedData?.workflowData, + executionFlattedData?.metadata, ); } catch { // Ignore errors diff --git a/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts b/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts index daf63c39a8..8eb9e0a75a 100644 --- a/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts +++ b/packages/cli/src/eventbus/MessageEventBusDestination/MessageEventBusDestinationWebhook.ee.ts @@ -359,7 +359,11 @@ export class MessageEventBusDestinationWebhook } } } catch (error) { - console.error(error); + LoggerProxy.warn( + `Webhook destination ${this.label} failed to send message to: ${this.url} - ${ + (error as Error).message + }`, + ); } return sendResult;