feat: add automatic TenantId logging to Logger default properties#2471
feat: add automatic TenantId logging to Logger default properties#2471Pratapchandradeo wants to merge 1 commit intoaws-powertools:mainfrom
Conversation
- Add TENANT_ID to PowertoolsLoggedFields enum with null-safety checks - Create TENANT_ID_RESOLVER in Log4j2 PowertoolsResolver with isResolvable check - Register TENANT_ID resolver in eventResolverMap for Log4j2 support - Add TENANT_ID_ATTR_NAME constant to LambdaEcsEncoder (ECS format: tenant.id) - Add conditional null-safe serialization of tenant_id in Logback ECS encoder - Update LambdaJsonLayout.json to include tenant_id field for Log4j2 JSON - Update LambdaEcsLayout.json to include tenant.id field for Log4j2 ECS - Update LambdaJsonEncoder JavaDoc to include tenant_id in listed fields - Add getTenantId() override in TestLambdaContext test stub - Update test assertions in LambdaJsonEncoderTest to verify tenant_id in output Fixes: aws-powertools#2348 References: aws-powertools#2358 This implementation follows AWS Lambda Tenant Isolation feature requirements and applies null-safety patterns consistent with correlation_id handling.
|
|
No acknowledgement section found. Please make sure you used the template to open a PR and didn't remove the acknowledgment section. Check the template at |
|
Hey @Pratapchandradeo thanks for opening this PR. Please check the PR template before we can proceed with the review: https://github.com/aws-powertools/powertools-lambda-java/blob/main/.github/PULL_REQUEST_TEMPLATE.md. |
phipag
left a comment
There was a problem hiding this comment.
Also some first comments on the code :-)
| hashMap.put(FUNCTION_MEMORY_SIZE.name, String.valueOf(context.getMemoryLimitInMB())); | ||
| hashMap.put(FUNCTION_REQUEST_ID.name, String.valueOf(context.getAwsRequestId())); | ||
| String tenantId = context.getTenantId(); | ||
| if (tenantId != null && !tenantId.isEmpty()) { |
There was a problem hiding this comment.
Can we add a unit test for tenantId being null and empty?
| } | ||
|
|
||
| String tenantId = mdcPropertyMap.get(TENANT_ID.getName()); | ||
| if (tenantId != null) { |
There was a problem hiding this comment.
I think we should check for both null and empty string similar to the PowertoolsLoggedFields.
| public boolean isResolvable(LogEvent logEvent) { | ||
| final String tenantId = | ||
| logEvent.getContextData().getValue(PowertoolsLoggedFields.TENANT_ID.getName()); | ||
| return null != tenantId; |
There was a problem hiding this comment.
I think we should check for both null and empty string similar to the PowertoolsLoggedFields.



Description
This PR adds support for AWS Lambda Tenant Isolation feature by automatically logging
tenant_idfrom the Lambda context to all logging outputs.What Changed
Fixes #2348
Acknowledgment