feat(core): Add metadata (customdata) to event log (#6334)

* add metadata (customdata) to event log

* lint fix

* use reduce
This commit is contained in:
Michael Auerswald 2023-05-30 17:59:55 +02:00 committed by GitHub
parent f91d36cd30
commit 792b1c1ffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -31,6 +31,7 @@ import type { User } from '@db/entities/User';
import { N8N_VERSION } from '@/constants'; import { N8N_VERSION } from '@/constants';
import * as Db from '@/Db'; import * as Db from '@/Db';
import { NodeTypes } from './NodeTypes'; import { NodeTypes } from './NodeTypes';
import type { ExecutionMetadata } from './databases/entities/ExecutionMetadata';
function userToPayload(user: User): { function userToPayload(user: User): {
userId: string; userId: string;
@ -253,7 +254,17 @@ export class InternalHooks implements IInternalHooksClass {
executionId: string, executionId: string,
executionMode: WorkflowExecuteMode, executionMode: WorkflowExecuteMode,
workflowData?: IWorkflowBase, workflowData?: IWorkflowBase,
executionMetadata?: ExecutionMetadata[],
): Promise<void> { ): Promise<void> {
let metaData;
try {
if (executionMetadata) {
metaData = executionMetadata.reduce((acc, meta) => {
return { ...acc, [meta.key]: meta.value };
}, {});
}
} catch {}
void Promise.all([ void Promise.all([
eventBus.sendWorkflowEvent({ eventBus.sendWorkflowEvent({
eventName: 'n8n.workflow.crashed', eventName: 'n8n.workflow.crashed',
@ -262,6 +273,7 @@ export class InternalHooks implements IInternalHooksClass {
isManual: executionMode === 'manual', isManual: executionMode === 'manual',
workflowId: workflowData?.id?.toString(), workflowId: workflowData?.id?.toString(),
workflowName: workflowData?.name, workflowName: workflowData?.name,
metaData,
}, },
}), }),
]); ]);
@ -430,6 +442,7 @@ export class InternalHooks implements IInternalHooksClass {
workflowId: properties.workflow_id, workflowId: properties.workflow_id,
isManual: properties.is_manual, isManual: properties.is_manual,
workflowName: workflow.name, workflowName: workflow.name,
metaData: runData?.data?.resultData?.metadata,
}, },
}) })
: eventBus.sendWorkflowEvent({ : eventBus.sendWorkflowEvent({
@ -445,6 +458,7 @@ export class InternalHooks implements IInternalHooksClass {
errorMessage: properties.error_message?.toString(), errorMessage: properties.error_message?.toString(),
isManual: properties.is_manual, isManual: properties.is_manual,
workflowName: workflow.name, workflowName: workflow.name,
metaData: runData?.data?.resultData?.metadata,
}, },
}), }),
); );

View file

@ -133,6 +133,7 @@ export class WorkflowRunner {
executionId, executionId,
executionMode, executionMode,
executionFlattedData?.workflowData, executionFlattedData?.workflowData,
executionFlattedData?.metadata,
); );
} catch { } catch {
// Ignore errors // Ignore errors

View file

@ -359,7 +359,11 @@ export class MessageEventBusDestinationWebhook
} }
} }
} catch (error) { } catch (error) {
console.error(error); LoggerProxy.warn(
`Webhook destination ${this.label} failed to send message to: ${this.url} - ${
(error as Error).message
}`,
);
} }
return sendResult; return sendResult;