Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log aws request id #133

Merged
merged 2 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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