Skip to content

Commit

Permalink
Add debug log on task run end (#131639)
Browse files Browse the repository at this point in the history
* Add debug log on task run end
  • Loading branch information
ersin-erdal authored May 10, 2022
1 parent 7bed8e8 commit 2a51a37
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,54 @@ describe('TaskManagerRunner', () => {
`Skipping reschedule for task bar \"${id}\" due to the task expiring`
);
});

test('Prints debug logs on task start/end', async () => {
const { runner, logger } = await readyToRunStageSetup({
definitions: {
bar: {
title: 'Bar!',
createTaskRunner: () => ({
async run() {
return { state: {} };
},
}),
},
},
});
await runner.run();

expect(logger.debug).toHaveBeenCalledTimes(2);
expect(logger.debug).toHaveBeenNthCalledWith(1, 'Running task bar "foo"', {
tags: ['task:start', 'foo', 'bar'],
});
expect(logger.debug).toHaveBeenNthCalledWith(2, 'Task bar "foo" ended', {
tags: ['task:end', 'foo', 'bar'],
});
});

test('Prints debug logs on task start/end even if it throws error', async () => {
const { runner, logger } = await readyToRunStageSetup({
definitions: {
bar: {
title: 'Bar!',
createTaskRunner: () => ({
async run() {
throw new Error();
},
}),
},
},
});
await runner.run();

expect(logger.debug).toHaveBeenCalledTimes(2);
expect(logger.debug).toHaveBeenNthCalledWith(1, 'Running task bar "foo"', {
tags: ['task:start', 'foo', 'bar'],
});
expect(logger.debug).toHaveBeenNthCalledWith(2, 'Task bar "foo" ended', {
tags: ['task:end', 'foo', 'bar'],
});
});
});

interface TestOpts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class TaskManagerRunner implements TaskRunner {
}`
);
}
this.logger.debug(`Running task ${this}`);
this.logger.debug(`Running task ${this}`, { tags: ['task:start', this.id, this.taskType] });

const apmTrans = apm.startTransaction(this.taskType, TASK_MANAGER_RUN_TRANSACTION_TYPE, {
childOf: this.instance.task.traceparent,
Expand Down Expand Up @@ -324,6 +324,8 @@ export class TaskManagerRunner implements TaskRunner {
);
if (apmTrans) apmTrans.end('failure');
return processedResult;
} finally {
this.logger.debug(`Task ${this} ended`, { tags: ['task:end', this.id, this.taskType] });
}
}

Expand Down

0 comments on commit 2a51a37

Please sign in to comment.