Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug log on task run end #131639

Merged
merged 4 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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