generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 176
Open
Labels
confirmedThe scope is clear, ready for implementationThe scope is clear, ready for implementationfeature-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 Utility
Description
Use case
The InvokeStore pacakge, allow for the use of Asynchronous contexts in lambda handlers. We should allow users to emit log statements in async contexts across lambda executions so that they are isolated.
Solution/User Experience
Lambda handlers in the runtime are automatically wrapped in this context, this can be replicated locally like so:
const logger = new Logger({
serviceName: 'serverlessAirline',
});
const processTransaction = async (customerId: string): Promise<void> => {
try {
// This log key with customerId will be scoped only to this handler execution and will not be available in any other invocations
logger.appendKeys({
customerId,
});
// ... your business logic
logger.info('transaction processed');
} finally {
logger.resetKeys();
}
};
export const handler = async (
event: { customerId: string },
_context: unknown
): Promise<void> => {
await processTransaction(event.customerId);
// .. other business logic
logger.info('other business logic processed');
};
// ...
const result = InvokeStore.run(
{
[InvokeStore.PROTECTED_KEYS.REQUEST_ID]: "request-123",
[InvokeStore.PROTECTED_KEYS.X_RAY_TRACE_ID]: "trace-456", // Optional X-Ray trace ID
customField: "value", // Optional custom fields
},
() => {
return handler(event)
}
);Alternative solutions
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
confirmedThe scope is clear, ready for implementationThe scope is clear, ready for implementationfeature-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 Utility