powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Feature request: Add tentant_id field to Context object and propagate to logger

Open leandrodamascena opened this issue 6 months ago • 1 comments

Use case

AWS Lambda RIC added a new field called tenantId and we need to add this field to the context. This must be a optional String and must check if tenantId is present in the context.

I tested with some functions and it's present while in others it's not.

Solution/User Experience

Add this field to the Context object and log it when injecting Lambda context.

Alternative solutions


Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

leandrodamascena avatar Jun 12 '25 12:06 leandrodamascena

Thanks, sounds good.

I'll put this on hold for now, and we'll work on it next month.

dreamorosi avatar Jun 12 '25 12:06 dreamorosi

Need to check if the new field is present in the context already or not.

dreamorosi avatar Jul 14 '25 13:07 dreamorosi

Verified that the field is present in the runtime, below an example:

 {
  callbackWaitsForEmptyEventLoop: [Getter/Setter],
  succeed: [Function (anonymous)],
  fail: [Function (anonymous)],
  done: [Function (anonymous)],
  functionVersion: '$LATEST',
  functionName: 'TenantFn',
  memoryLimitInMB: '128',
  logGroupName: '/aws/lambda/TenantFn',
  logStreamName: '2025/07/15/TenantFn[$LATEST]5fe3c6d22b44430e91840af6f6304cd3',
  clientContext: undefined,
  identity: undefined,
  invokedFunctionArn: 'arn:aws:lambda:eu-west-1:536254204126:function:TenantFn',
  awsRequestId: 'cc3f97fc-219b-4cbf-86f0-d75763154364',
  tenantId: undefined,
  getRemainingTimeInMillis: [Function: getRemainingTimeInMillis]
}

dreamorosi avatar Jul 15 '25 17:07 dreamorosi

Opened a PR to the @types/aws-lambda repo to add this type for all customers: DefinitelyTyped/DefinitelyTyped#73265

dreamorosi avatar Jul 15 '25 17:07 dreamorosi

PR was merged and the type including the new key has been published 2 days ago under version 8.10.152 (see here).

Since we're not adding the key to the logger when appending the context, I'm closing the issue as completed.

dreamorosi avatar Jul 21 '25 12:07 dreamorosi

[!warning] This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either reopen the issue, or open a new issue referencing this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.