Skip to content

Conversation

@kawaaaas
Copy link
Contributor

@kawaaaas kawaaaas commented Jan 8, 2026

Summary

Changes

This PR adds support for the new AWS Lambda Tenant Isolation feature by including tenantId from the Lambda context as a default property in Logger output.

When a Lambda function is invoked with tenant isolation enabled, the tenantId will automatically be included in all log entries as tenant_id, making it easier to trace and filter logs in multi-tenant environments.

Issue number: closes #4914

Implementation Details

  • Added tenantId to LambdaFunctionContext type in logKeys.ts
  • Added tenant_id to PowertoolsLambdaContextKeys type
  • Updated addContext() method in Logger.ts to extract tenantId from Lambda context
  • Updated PowertoolsLogFormatter.ts to include tenant_id in formatted output
  • Added test coverage for both scenarios (with and without tenantId)
  • Updated testing utilities to include tenantId in mock context

Please let me know if there are any points that need correction or if there is anything I should improve before merging.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added logger This item relates to the Logger Utility tests PRs that add or change tests labels Jan 8, 2026
@pull-request-size pull-request-size bot added the size/M PR between 30-99 LOC label Jan 8, 2026
svozza
svozza previously approved these changes Jan 8, 2026
@svozza
Copy link
Contributor

svozza commented Jan 8, 2026

Thank you for the PR, looks good to me!

@svozza svozza dismissed their stale review January 8, 2026 21:59

Need to update middy test

@svozza
Copy link
Contributor

svozza commented Jan 8, 2026

Actually, just one thing. Can we update the middy tests here to check the tenant ID:

const getContextLogEntries = (overrides?: Record<string, unknown>) => ({

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 9, 2026

@kawaaaas
Copy link
Contributor Author

kawaaaas commented Jan 9, 2026

@svozza
Thanks for the catch!

I've added a test case for Middy to check the scenario where tenant_id is missing. The case where it’s present should already be covered by existing tests.

Also, I've fixed an oversight where tenant_id was missing from other context-related tests. I didn't include it in the E2E tests though, as it's an optional field.

Please let me know if there are any other test cases or scenarios I should consider.

@svozza
Copy link
Contributor

svozza commented Jan 9, 2026

Good stuff. Don't worry about the E2E test for now, we can add that later. Great work!

@svozza svozza merged commit 2e3e867 into aws-powertools:main Jan 9, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logger This item relates to the Logger Utility size/M PR between 30-99 LOC tests PRs that add or change tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add TenantId to Logger default properties

2 participants