aws / aws/aws-lambda-java-libs

Pass Lambda RequestID to SLF4J MDC as well

Open
#265 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
548
Forks
241
Avg merge
2d 5m
Merged PRs (30d)
11

Description

https://github.com/aws/aws-lambda-java-libs/blob/master/aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/EventHandlerLoader.java#L888

Here, code checks for log4j 1/2 MDC classes to set the `AWSRequestId` property so it can be used in the logs.
New Java v2 SDK comes with `slf4j-api` which is heavily used as a logging face for many loggers, including log4j 1/2 but also Logback etc.

Addding a call for `org.slf4j.MDC.put` will help passing the requestID to slf4j context so any implementation can be used freely. Since package size is important, comparing ~2MB size of Log4j2, user can choose any logging implementation using slf4j as facade.

Method name a little misleading, `LambdaRuntimeInternal.setUseLog4jAppender` but this can be ignored I believe or changed as `setUseLoggingAppender` or adding the ability to pass the class name to call the `put` method on, whichever easier/logical.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.