diff --git a/packages/cpsuLambda/src/handler.ts b/packages/cpsuLambda/src/handler.ts index c3d835483..446c47f00 100644 --- a/packages/cpsuLambda/src/handler.ts +++ b/packages/cpsuLambda/src/handler.ts @@ -59,7 +59,11 @@ function append_headers(headers: Record, logger: Logger) { if (headers["x-correlation-id"]) { headers_to_append["x-correlation-id"] = headers["x-correlation-id"] } + if (headers["x-request-id"]) { + headers_to_append["x-request-id"] = headers["x-request-id"] + } logger.appendKeys(headers_to_append) + logger.info("added headers to logger for tracing", {headers_to_append}) } /** diff --git a/packages/cpsuLambda/tests/testHandler.test.ts b/packages/cpsuLambda/tests/testHandler.test.ts index 2ec937396..191634aae 100644 --- a/packages/cpsuLambda/tests/testHandler.test.ts +++ b/packages/cpsuLambda/tests/testHandler.test.ts @@ -33,7 +33,8 @@ describe("generic handler", () => { "apigw-request-id": "test-apigw-request-id", "nhsd-correlation-id": "test-nhsd-correlation-id", "nhsd-request-id": "test-nhsd-request-id", - "x-correlation-id": "test-x-correlation-id" + "x-correlation-id": "test-x-correlation-id", + "x-request-id": "test-x-request-id" } } @@ -62,6 +63,7 @@ describe("generic handler", () => { expect(logger_call["nhsd-correlation-id"]).toEqual("test-nhsd-correlation-id") expect(logger_call["nhsd-request-id"]).toEqual("test-nhsd-request-id") expect(logger_call["x-correlation-id"]).toEqual("test-x-correlation-id") + expect(logger_call["x-request-id"]).toEqual("test-x-request-id") }) })