Skip to content

Commit

Permalink
feat: log aws request id (aws-powertools#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajagrawal16 authored and jeromevdl committed Oct 19, 2020
1 parent 27d608f commit 46587fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/content/core/logging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -41,6 +42,7 @@ static Map<String, String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object, Object> requestHandler;

Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 46587fc

Please sign in to comment.