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

[8.x] Enhance task failure log to include error source in tags (#199406) #200082

Merged
merged 2 commits into from
Nov 14, 2024
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 @@ -930,9 +930,33 @@ describe('TaskManagerRunner', () => {
const loggerCall = logger.error.mock.calls[0][0];
const loggerMeta = logger.error.mock.calls[0][1];
expect(loggerCall as string).toMatchInlineSnapshot(`"Task bar \\"foo\\" failed: Error: rar"`);
expect(loggerMeta?.tags).toEqual(['bar', 'foo', 'task-run-failed']);
expect(loggerMeta?.tags).toEqual(['bar', 'foo', 'task-run-failed', 'framework-error']);
expect(loggerMeta?.error?.stack_trace).toBeDefined();
});
test('logs user errors as expected when task fails', async () => {
const { runner, logger } = await readyToRunStageSetup({
instance: {
params: { a: 'b' },
state: { hey: 'there' },
},
definitions: {
bar: {
title: 'Bar!',
createTaskRunner: () => ({
async run() {
throw createTaskRunError(new Error('rar'), TaskErrorSource.USER);
},
}),
},
},
});
await runner.run();

const loggerCall = logger.error.mock.calls[0][0];
const loggerMeta = logger.error.mock.calls[0][1];
expect(loggerCall as string).toMatchInlineSnapshot(`"Task bar \\"foo\\" failed: Error: rar"`);
expect(loggerMeta?.tags).toEqual(['bar', 'foo', 'task-run-failed', 'user-error']);
});
test('provides execution context on run', async () => {
const { runner } = await readyToRunStageSetup({
definitions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ import {
TaskStatus,
} from '../task';
import { TaskTypeDictionary } from '../task_type_dictionary';
import { isUnrecoverableError } from './errors';
import { isUnrecoverableError, isUserError } from './errors';
import { CLAIM_STRATEGY_MGET, type TaskManagerConfig } from '../config';
import { TaskValidator } from '../task_validator';
import { getRetryAt, getRetryDate, getTimeout } from '../lib/get_retry_at';
import { getNextRunAt } from '../lib/get_next_run_at';
import { TaskErrorSource } from '../../common/constants';

export const EMPTY_RUN_RESULT: SuccessfulRunResult = { state: {} };

Expand Down Expand Up @@ -397,8 +398,9 @@ export class TaskManagerRunner implements TaskRunner {
if (apmTrans) apmTrans.end('success');
return processedResult;
} catch (err) {
const errorSource = isUserError(err) ? TaskErrorSource.USER : TaskErrorSource.FRAMEWORK;
this.logger.error(`Task ${this} failed: ${err}`, {
tags: [this.taskType, this.instance.task.id, 'task-run-failed'],
tags: [this.taskType, this.instance.task.id, 'task-run-failed', `${errorSource}-error`],
error: { stack_trace: err.stack },
});
// in error scenario, we can not get the RunResult
Expand Down