Skip to content

Logger: appendKeys and promises #3385

Answered by dreamorosi
matthelliwell2 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @matthelliwell2, as you've noticed the Logger instance as of today has only one context/bag of attributes.

In your case, you're running a number of promises in parallel, so they're all appending/removing keys from the same instance, this is why keys are getting mixed and/or deleted.

As you already hinted at, the solution would be to create child loggers for each one of your parallel tasks:

import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ logLevel: 'debug' });

export async function handler(event: SQSEvent): Promise<SQSBatchResponse> {
    logger.appendKeys({ foo: 'bar' });

    const promises = event.Records.map(async r => {
        const taskLogger = 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by matthelliwell2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants