Skip to content

Commit 35dfe2e

Browse files
committed
Add eventCode to event input
1 parent 4cd020f commit 35dfe2e

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

packages/integration-sdk-core/src/types/logger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export type IntegrationEvent = {
4040
export type PublishEventInput = {
4141
name: string;
4242
description: string;
43+
/**
44+
* Allows the event to be identified via a code.
45+
*/
46+
eventCode?: string;
4347
level?: PublishEventLevel;
4448
};
4549

packages/integration-sdk-runtime/src/logger/__tests__/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ describe('step event publishing', () => {
368368
expect(onEmitEvent).toHaveBeenNthCalledWith(8, {
369369
name: 'step_failure',
370370
level: PublishEventLevel.Error,
371+
eventCode: expect.toBeString(),
371372
description: expect.stringMatching(
372373
new RegExp(
373374
`Step "Mochi" failed to complete due to error. \\(errorCode="${error.code}", reason="ripperoni"\\)$`,
@@ -423,6 +424,7 @@ describe('provider auth error details', () => {
423424
expect(onEmitEvent).toHaveBeenCalledWith({
424425
name: 'step_failure',
425426
level: PublishEventLevel.Error,
427+
eventCode: expect.toBeString(),
426428
description: expect.stringMatching(
427429
new RegExp(
428430
'^Step "Mochi" failed to complete due to error.' +
@@ -439,6 +441,7 @@ describe('provider auth error details', () => {
439441
expect(onEmitEvent).toHaveBeenCalledWith({
440442
name: 'validation_failure',
441443
level: PublishEventLevel.Error,
444+
eventCode: expect.toBeString(),
442445
description: expect.stringMatching(
443446
new RegExp(
444447
'^Error occurred while validating integration configuration.' +
@@ -503,6 +506,7 @@ describe('validation failure logging', () => {
503506
expect(onEmitEvent).toHaveBeenNthCalledWith(1, {
504507
name: 'validation_failure',
505508
level: PublishEventLevel.Error,
509+
eventCode: expect.toBeString(),
506510
description: expect.stringMatching(expectedDescriptionRegex),
507511
});
508512

@@ -535,6 +539,7 @@ describe('validation failure logging', () => {
535539
expect(onEmitEvent).toHaveBeenNthCalledWith(1, {
536540
name: 'validation_failure',
537541
level: PublishEventLevel.Error,
542+
eventCode: expect.toBeString(),
538543
description: expect.stringMatching(expectedDescriptionRegex),
539544
});
540545

@@ -731,13 +736,15 @@ describe('#publishEvent', () => {
731736
logger.publishWarnEvent({
732737
name: IntegrationWarnEventName[key],
733738
description: 'the description',
739+
eventCode: 'AWS-PER-ECS',
734740
});
735741

736742
expect(onEmitEvent).toHaveBeenCalledTimes(1);
737743
expect(onEmitEvent).toHaveBeenCalledWith({
738744
name: IntegrationWarnEventName[key],
739745
level: PublishEventLevel.Warn,
740746
description: 'the description',
747+
eventCode: 'AWS-PER-ECS',
741748
});
742749
},
743750
);
@@ -756,6 +763,7 @@ describe('#publishEvent', () => {
756763
logger.publishErrorEvent({
757764
name: IntegrationErrorEventName[key],
758765
description: 'the description',
766+
eventCode: 'AWS-PER-ECS',
759767
});
760768

761769
expect(onEmitEvent).toHaveBeenCalledTimes(1);
@@ -764,6 +772,7 @@ describe('#publishEvent', () => {
764772
name: IntegrationErrorEventName[key],
765773
level: PublishEventLevel.Error,
766774
description: 'the description',
775+
eventCode: 'AWS-PER-ECS',
767776
});
768777
},
769778
);

packages/integration-sdk-runtime/src/logger/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class IntegrationLogger
194194
}
195195

196196
/**
197-
* Answers `true` when the err has been reported to the logger instance
197+
* Answers `true` when the error has been reported to the logger instance
198198
* through these functions:
199199
*
200200
* * warn(err, ...)
@@ -366,11 +366,17 @@ export class IntegrationLogger
366366

367367
stepFailure(step: StepMetadata, err: Error) {
368368
const eventName = 'step_failure';
369-
const { errorId, description } = createErrorEventDescription(
369+
const { errorId, errorCode, description } = createErrorEventDescription(
370370
err,
371371
`Step "${step.name}" failed to complete due to error.`,
372372
);
373-
this.handleFailure({ eventName, errorId, err, description });
373+
this.handleFailure({
374+
eventName,
375+
errorId,
376+
eventCode: errorCode,
377+
err,
378+
description,
379+
});
374380
}
375381

376382
synchronizationUploadStart(job: SynchronizationJob) {
@@ -399,20 +405,27 @@ export class IntegrationLogger
399405

400406
validationFailure(err: Error) {
401407
const eventName = 'validation_failure';
402-
const { errorId, description } = createErrorEventDescription(
408+
const { errorId, errorCode, description } = createErrorEventDescription(
403409
err,
404410
`Error occurred while validating integration configuration.`,
405411
);
406-
this.handleFailure({ eventName, errorId, err, description });
412+
this.handleFailure({
413+
eventName,
414+
errorId,
415+
eventCode: errorCode,
416+
err,
417+
description,
418+
});
407419
}
408420

409421
private handleFailure(options: {
410422
eventName: 'validation_failure' | 'step_failure';
411423
errorId: string;
424+
eventCode: string;
412425
err: Error;
413426
description: string;
414427
}) {
415-
const { eventName, errorId, err, description } = options;
428+
const { eventName, errorId, eventCode, err, description } = options;
416429

417430
// If there is a `code` property on the `Error`, we should include this
418431
// in our log. This is helpful for when we receive an HTTP response error
@@ -429,6 +442,7 @@ export class IntegrationLogger
429442
this.publishEvent({
430443
name: eventName,
431444
description,
445+
eventCode,
432446
level: PublishEventLevel.Error,
433447
});
434448
}
@@ -529,6 +543,7 @@ export function createErrorEventDescription(
529543

530544
return {
531545
errorId,
546+
errorCode,
532547
description: `${message} (${errorDetails})`,
533548
};
534549
}

0 commit comments

Comments
 (0)