diff --git a/docs/content/core/logging.mdx b/docs/content/core/logging.mdx index a5e33c352..05cd172e4 100644 --- a/docs/content/core/logging.mdx +++ b/docs/content/core/logging.mdx @@ -70,6 +70,7 @@ Key | Type | Example | Description **functionMemorySize**| String | "128" **functionArn**| String | "arn:aws:lambda:eu-west-1:012345678910:function:example-powertools-HelloWorldFunction-1P1Z6B39FLU73" **xray_trace_id**| String | "1-5759e988-bd862e3fe1be46a994272793" | X-Ray Trace ID when Lambda function has enabled Tracing +**function_request_id**| String | "899856cb-83d1-40d7-8611-9e78f15f32f4"" | AWS Request ID from lambda context ## Capturing context Lambda info diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/DefaultLambdaFields.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/DefaultLambdaFields.java index 8a5d3a289..a50b292b2 100644 --- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/DefaultLambdaFields.java +++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/DefaultLambdaFields.java @@ -22,7 +22,8 @@ enum DefaultLambdaFields { FUNCTION_NAME("functionName"), FUNCTION_VERSION("functionVersion"), FUNCTION_ARN("functionArn"), - FUNCTION_MEMORY_SIZE("functionMemorySize"); + FUNCTION_MEMORY_SIZE("functionMemorySize"), + FUNCTION_REQUEST_ID("function_request_id"); private final String name; @@ -41,6 +42,7 @@ static Map values(Context context) { hashMap.put(FUNCTION_VERSION.name, context.getFunctionVersion()); hashMap.put(FUNCTION_ARN.name, context.getInvokedFunctionArn()); hashMap.put(FUNCTION_MEMORY_SIZE.name, String.valueOf(context.getMemoryLimitInMB())); + hashMap.put(FUNCTION_REQUEST_ID.name, String.valueOf(context.getAwsRequestId())); return hashMap; } diff --git a/powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java b/powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java index 71f1dcec9..7f38db0a7 100644 --- a/powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java +++ b/powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java @@ -69,7 +69,7 @@ class LambdaLoggingAspectTest { - private static final int EXPECTED_CONTEXT_SIZE = 7; + private static final int EXPECTED_CONTEXT_SIZE = 8; private RequestStreamHandler requestStreamHandler; private RequestHandler requestHandler; @@ -99,6 +99,7 @@ void shouldSetLambdaContextWhenEnabled() { .containsEntry(DefaultLambdaFields.FUNCTION_MEMORY_SIZE.getName(), "10") .containsEntry(DefaultLambdaFields.FUNCTION_VERSION.getName(), "1") .containsEntry(DefaultLambdaFields.FUNCTION_NAME.getName(), "testFunction") + .containsEntry(DefaultLambdaFields.FUNCTION_REQUEST_ID.getName(), "RequestId") .containsKey("coldStart") .containsKey("service"); } @@ -115,6 +116,7 @@ void shouldSetLambdaContextForStreamHandlerWhenEnabled() throws IOException { .containsEntry(DefaultLambdaFields.FUNCTION_MEMORY_SIZE.getName(), "10") .containsEntry(DefaultLambdaFields.FUNCTION_VERSION.getName(), "1") .containsEntry(DefaultLambdaFields.FUNCTION_NAME.getName(), "testFunction") + .containsEntry(DefaultLambdaFields.FUNCTION_REQUEST_ID.getName(), "RequestId") .containsKey("coldStart") .containsKey("service"); } @@ -232,6 +234,7 @@ private void setupContext() { when(context.getInvokedFunctionArn()).thenReturn("testArn"); when(context.getFunctionVersion()).thenReturn("1"); when(context.getMemoryLimitInMB()).thenReturn(10); + when(context.getAwsRequestId()).thenReturn("RequestId"); } private void resetLogLevel(Level level) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {