Open
Description
Use case
Currently if you want to context in async workflows you have to pass child loggers to the methods you call
const tasks = batch.map(async (id) => {
doWork(id, { logger: logger.createChild() })
})
await Promise.all(tasks)
Solution/User Experience
We could use node's AsyncLocalStorage to save the 'current' logger, and functions could fetch the logger from the store
This could be combined with explicit resource management to allow writing code like
const handler = (event, context) => {
using logger = withContext(context)
const tasks = event.batch.map(doWork)
await Promise.all(tasks)
}
async function doWork(task: Task) {
using logger = withAdditionalKeys({ id: task.id })
await step1(task)
await step2(task)
}
async function step1(task: Task) {
using logger = withAdditionalKeys({ step: "1" )
logger.info()
}
Alternative solutions
This can be built ad-hoc but would be better to include in the library.
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Ideas