-
Notifications
You must be signed in to change notification settings - Fork 168
Open
Labels
feature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utilityloggerThis item relates to the Logger UtilityThis item relates to the Logger Utilityon-holdThis item is on-hold and will be revisited in the futureThis item is on-hold and will be revisited in the future
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
feature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utilityloggerThis item relates to the Logger UtilityThis item relates to the Logger Utilityon-holdThis item is on-hold and will be revisited in the futureThis item is on-hold and will be revisited in the future
Type
Projects
Status
Ideas