Improve logs in workflow trigger (#12215)

- distinguish logs coming from webhook and job triggers
- add workspace and workflow ids to help debugging

Hard to debug sentry issue:

https://twenty-v7.sentry.io/issues/6605607134/?project=4507072499810304&query=&referrer=issue-stream&stream_index=7
This commit is contained in:
Thomas Trompette
2025-05-22 14:56:30 +02:00
committed by GitHub
parent 0f9cdd9d39
commit 4ac47c2a1b
2 changed files with 22 additions and 12 deletions

View File

@ -28,23 +28,33 @@ export class WorkflowTriggerController {
@Post('workflows/:workspaceId/:workflowId') @Post('workflows/:workspaceId/:workflowId')
async runWorkflowByPostRequest( async runWorkflowByPostRequest(
@Param('workspaceId') workspaceId: string,
@Param('workflowId') workflowId: string, @Param('workflowId') workflowId: string,
@Req() request: Request, @Req() request: Request,
) { ) {
return await this.runWorkflow({ workflowId, payload: request.body || {} }); return await this.runWorkflow({
workflowId,
payload: request.body || {},
workspaceId,
});
} }
@Get('workflows/:workspaceId/:workflowId') @Get('workflows/:workspaceId/:workflowId')
async runWorkflowByGetRequest(@Param('workflowId') workflowId: string) { async runWorkflowByGetRequest(
return await this.runWorkflow({ workflowId }); @Param('workspaceId') workspaceId: string,
@Param('workflowId') workflowId: string,
) {
return await this.runWorkflow({ workflowId, workspaceId });
} }
private async runWorkflow({ private async runWorkflow({
workflowId, workflowId,
payload, payload,
workspaceId,
}: { }: {
workflowId: string; workflowId: string;
payload?: object; payload?: object;
workspaceId: string;
}) { }) {
const workflowRepository = const workflowRepository =
await this.twentyORMManager.getRepository<WorkflowWorkspaceEntity>( await this.twentyORMManager.getRepository<WorkflowWorkspaceEntity>(
@ -57,7 +67,7 @@ export class WorkflowTriggerController {
if (!isDefined(workflow)) { if (!isDefined(workflow)) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow not found', `[Webhook trigger] Workflow ${workflowId} not found in workspace ${workspaceId}`,
WorkflowTriggerExceptionCode.NOT_FOUND, WorkflowTriggerExceptionCode.NOT_FOUND,
); );
} }
@ -67,7 +77,7 @@ export class WorkflowTriggerController {
workflow.lastPublishedVersionId === '' workflow.lastPublishedVersionId === ''
) { ) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow has not been activated', `[Webhook trigger] Workflow ${workflowId} has not been activated in workspace ${workspaceId}`,
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_STATUS, WorkflowTriggerExceptionCode.INVALID_WORKFLOW_STATUS,
); );
} }
@ -82,21 +92,21 @@ export class WorkflowTriggerController {
if (!isDefined(workflowVersion)) { if (!isDefined(workflowVersion)) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow version not found', `[Webhook trigger] No workflow version activated for workflow ${workflowId} in workspace ${workspaceId}`,
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION, WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION,
); );
} }
if (workflowVersion.trigger?.type !== WorkflowTriggerType.WEBHOOK) { if (workflowVersion.trigger?.type !== WorkflowTriggerType.WEBHOOK) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow does not have a Webhook trigger', `[Webhook trigger] Workflow ${workflowId} does not have a Webhook trigger in workspace ${workspaceId}`,
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER, WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER,
); );
} }
if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) { if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow version is not active', `[Webhook trigger] Workflow version ${workflowVersion.id} is not active in workspace ${workspaceId}`,
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_STATUS, WorkflowTriggerExceptionCode.INVALID_WORKFLOW_STATUS,
); );
} }

View File

@ -52,14 +52,14 @@ export class WorkflowTriggerJob {
if (!workflow) { if (!workflow) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow not found', `Workflow ${data.workflowId} not found in workspace ${data.workspaceId}`,
WorkflowTriggerExceptionCode.NOT_FOUND, WorkflowTriggerExceptionCode.NOT_FOUND,
); );
} }
if (!workflow.lastPublishedVersionId) { if (!workflow.lastPublishedVersionId) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow has no published version', `Workflow ${data.workflowId} has no published version in workspace ${data.workspaceId}`,
WorkflowTriggerExceptionCode.INTERNAL_ERROR, WorkflowTriggerExceptionCode.INTERNAL_ERROR,
); );
} }
@ -75,13 +75,13 @@ export class WorkflowTriggerJob {
if (!workflowVersion) { if (!workflowVersion) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow version not found', `Workflow version ${workflow.lastPublishedVersionId} not found in workspace ${data.workspaceId}`,
WorkflowTriggerExceptionCode.NOT_FOUND, WorkflowTriggerExceptionCode.NOT_FOUND,
); );
} }
if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) { if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) {
throw new WorkflowTriggerException( throw new WorkflowTriggerException(
'Workflow version is not active', `Workflow version ${workflowVersion.id} is not active in workspace ${data.workspaceId}`,
WorkflowTriggerExceptionCode.INTERNAL_ERROR, WorkflowTriggerExceptionCode.INTERNAL_ERROR,
); );
} }