diff --git a/packages/integration-sdk-core/src/types/logger.ts b/packages/integration-sdk-core/src/types/logger.ts index 89676edbb..71b90d81c 100644 --- a/packages/integration-sdk-core/src/types/logger.ts +++ b/packages/integration-sdk-core/src/types/logger.ts @@ -40,6 +40,10 @@ export type IntegrationEvent = { export type PublishEventInput = { name: string; description: string; + /** + * Allows the event to be identified via a code. + */ + eventCode?: string; level?: PublishEventLevel; }; diff --git a/packages/integration-sdk-runtime/src/logger/__tests__/index.test.ts b/packages/integration-sdk-runtime/src/logger/__tests__/index.test.ts index 7b139d0c3..cac539b29 100644 --- a/packages/integration-sdk-runtime/src/logger/__tests__/index.test.ts +++ b/packages/integration-sdk-runtime/src/logger/__tests__/index.test.ts @@ -368,6 +368,7 @@ describe('step event publishing', () => { expect(onEmitEvent).toHaveBeenNthCalledWith(8, { name: 'step_failure', level: PublishEventLevel.Error, + eventCode: expect.toBeString(), description: expect.stringMatching( new RegExp( `Step "Mochi" failed to complete due to error. \\(errorCode="${error.code}", reason="ripperoni"\\)$`, @@ -423,6 +424,7 @@ describe('provider auth error details', () => { expect(onEmitEvent).toHaveBeenCalledWith({ name: 'step_failure', level: PublishEventLevel.Error, + eventCode: expect.toBeString(), description: expect.stringMatching( new RegExp( '^Step "Mochi" failed to complete due to error.' + @@ -439,6 +441,7 @@ describe('provider auth error details', () => { expect(onEmitEvent).toHaveBeenCalledWith({ name: 'validation_failure', level: PublishEventLevel.Error, + eventCode: expect.toBeString(), description: expect.stringMatching( new RegExp( '^Error occurred while validating integration configuration.' + @@ -503,6 +506,7 @@ describe('validation failure logging', () => { expect(onEmitEvent).toHaveBeenNthCalledWith(1, { name: 'validation_failure', level: PublishEventLevel.Error, + eventCode: expect.toBeString(), description: expect.stringMatching(expectedDescriptionRegex), }); @@ -535,6 +539,7 @@ describe('validation failure logging', () => { expect(onEmitEvent).toHaveBeenNthCalledWith(1, { name: 'validation_failure', level: PublishEventLevel.Error, + eventCode: expect.toBeString(), description: expect.stringMatching(expectedDescriptionRegex), }); @@ -731,6 +736,7 @@ describe('#publishEvent', () => { logger.publishWarnEvent({ name: IntegrationWarnEventName[key], description: 'the description', + eventCode: 'AWS-PER-ECS', }); expect(onEmitEvent).toHaveBeenCalledTimes(1); @@ -738,6 +744,7 @@ describe('#publishEvent', () => { name: IntegrationWarnEventName[key], level: PublishEventLevel.Warn, description: 'the description', + eventCode: 'AWS-PER-ECS', }); }, ); @@ -756,6 +763,7 @@ describe('#publishEvent', () => { logger.publishErrorEvent({ name: IntegrationErrorEventName[key], description: 'the description', + eventCode: 'AWS-PER-ECS', }); expect(onEmitEvent).toHaveBeenCalledTimes(1); @@ -764,6 +772,7 @@ describe('#publishEvent', () => { name: IntegrationErrorEventName[key], level: PublishEventLevel.Error, description: 'the description', + eventCode: 'AWS-PER-ECS', }); }, ); diff --git a/packages/integration-sdk-runtime/src/logger/index.ts b/packages/integration-sdk-runtime/src/logger/index.ts index 8ac4ff8bd..7c22d516b 100644 --- a/packages/integration-sdk-runtime/src/logger/index.ts +++ b/packages/integration-sdk-runtime/src/logger/index.ts @@ -204,7 +204,7 @@ export class IntegrationLogger } /** - * Answers `true` when the err has been reported to the logger instance + * Answers `true` when the error has been reported to the logger instance * through these functions: * * * warn(err, ...) @@ -376,11 +376,17 @@ export class IntegrationLogger stepFailure(step: StepMetadata, err: Error) { const eventName = 'step_failure'; - const { errorId, description } = createErrorEventDescription( + const { errorId, errorCode, description } = createErrorEventDescription( err, `Step "${step.name}" failed to complete due to error.`, ); - this.handleFailure({ eventName, errorId, err, description }); + this.handleFailure({ + eventName, + errorId, + eventCode: errorCode, + err, + description, + }); } synchronizationUploadStart(job: SynchronizationJob) { @@ -409,20 +415,27 @@ export class IntegrationLogger validationFailure(err: Error) { const eventName = 'validation_failure'; - const { errorId, description } = createErrorEventDescription( + const { errorId, errorCode, description } = createErrorEventDescription( err, `Error occurred while validating integration configuration.`, ); - this.handleFailure({ eventName, errorId, err, description }); + this.handleFailure({ + eventName, + errorId, + eventCode: errorCode, + err, + description, + }); } private handleFailure(options: { eventName: 'validation_failure' | 'step_failure'; errorId: string; + eventCode: string; err: Error; description: string; }) { - const { eventName, errorId, err, description } = options; + const { eventName, errorId, eventCode, err, description } = options; // If there is a `code` property on the `Error`, we should include this // in our log. This is helpful for when we receive an HTTP response error @@ -439,6 +452,7 @@ export class IntegrationLogger this.publishEvent({ name: eventName, description, + eventCode, level: PublishEventLevel.Error, }); } @@ -539,6 +553,7 @@ export function createErrorEventDescription( return { errorId, + errorCode, description: `${message} (${errorDetails})`, }; }