-
Notifications
You must be signed in to change notification settings - Fork 170
Closed
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedloggerThis item relates to the Logger UtilityThis item relates to the Logger Utility
Description
Bug description
When using addPersistentLogAttributes
:
logger.addPersistentLogAttributes({ memberId: 'test' });
and using the middy to clearState:
export const handler = middy(lambdaHandler).use(
injectLambdaContext(logger, { clearState: true })
);
and then exiting the lambda by throwing an error, the next invocation will still have the persistentLogAttributes present. My guess is that the middleware never runs because of the error.
Expected Behavior
When lambda crashes the middleware should still clearState
.
Current Behavior
When lambda crashes the middleware does not clearState
.
Possible Solution
I guess there could be a way of handling this by not using middleware but there is no documentation of how to clearState
without it.
Steps to Reproduce
- create handler like:
import { Handler } from 'aws-lambda';
import middy from '@middy/core';
import { injectLambdaContext, Logger } from '@aws-lambda-powertools/logger';
const logger = new Logger();
const lambdaHandler: Handler = async (event) => {
logger.info('Before adding memberId');
logger.addPersistentLogAttributes({ memberId: 'test' });
logger.info('After adding memberId');
throw new Error();
};
export const handler = middy(lambdaHandler).use(
injectLambdaContext(logger, { clearState: true })
);
- invoce lambda
- check logs,
Before adding memberId
will not have memberId property,After adding memberId
will have memberId: test - invoce lambda again
- check logs
Before adding memberId
will have memberId: test (which is not supposed to be there).
Environment
"@aws-lambda-powertools/logger": "^1.0.2",
"@middy/core": "^3.1.0"
Lambda runtime: nodejs16.x
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedloggerThis item relates to the Logger UtilityThis item relates to the Logger Utility