-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Feature Request
Native integration with AWS Lambda Powertools for TypeScript Logger, similar to how the Python Durable SDK supports Powertools.
Problem
When using Powertools Logger as a customLogger via context.configureLogger(), the logs get double-wrapped in CloudWatch because:
- Durable functions require
LogFormat: JSONin the Lambda config - Lambda's
LogFormat: JSONpatches the globalconsoleobject to wrap output in{"timestamp", "level", "requestId", "message"} - Powertools Logger uses the global
console.info()to output its own structured JSON - Lambda catches that and stringifies Powertools' JSON into the
messagefield
Result — double-wrapped JSON:
{
"timestamp": "2026-03-09T13:52:31.481Z",
"level": "INFO",
"requestId": "fa3b7f07-0be3-4380-9a53-fb080779fcf4",
"message": "{\n \"level\": \"INFO\",\n \"message\": \"workflow-started\",\n \"timestamp\": \"2026-03-09T19:22:31.039+05:30\",\n \"service\": \"lambda-user-account-deletion\",\n \"sampling_rate\": 0,\n \"xray_trace_id\": \"1-69aed09e-5a04f2fc1f7bee1748385655\",\n \"tm_user_id\": \"0199c820-c4bd-778a-9197-580108aea912\"\n}"
}Workaround
Override the Powertools Logger's internal console with a direct process.stdout writer (same technique the Durable SDK's own DefaultLogger uses and Powertools itself uses):
import { Console } from 'node:console';
import { Logger } from '@aws-lambda-powertools/logger';
const logger = new Logger({ serviceName: 'my-service' });
// Bypass Lambda's LogFormat:JSON console patching to prevent double-wrapped JSON logs
(logger as unknown as { console: Console }).console = new Console({
stdout: process.stdout,
stderr: process.stderr,
});
export { logger };Then pass it as customLogger:
const handler = async (event: MyEvent, context: DurableContext<Logger>) => {
context.configureLogger({ customLogger: logger });
context.logger.info({ message: 'workflow-started' });
};
export const myFunction = withDurableExecution(handler);Result — clean Powertools output:
{
"level": "INFO",
"message": "workflow-started",
"timestamp": "2026-03-09T19:37:51.268+05:30",
"service": "my-service",
"sampling_rate": 0,
"xray_trace_id": "1-69aed434-506caa866976504e1a0ec55f"
}Requested Feature
-
First-class Powertools integration — The Python Durable SDK has native Powertools support where
context.configure_logger(powertools_logger)automatically injects durable execution metadata (executionArn,operationId,attempt,requestId) into every Powertools log entry viaappend_keys(). The JS SDK should have parity. -
Handle the console patching conflict — When Powertools is detected as the
customLogger, the SDK should automatically handle theLogFormat: JSONconsole patching conflict so users don't need the workaround above. -
Inject durable metadata into Powertools structured logs — Use Powertools'
appendKeys()method to inject durable execution context (likeexecutionArn,operationId) into every log entry automatically, rather than just delegating log calls.
Environment
- SDK Version: latest
- Node.js: 24.x
- Powertools: @aws-lambda-powertools/logger v2
- Runtime: Durable Function (nodejs:24.DurableFunction.v10)
References
- Python SDK Powertools integration: https://github.com/aws/aws-durable-execution-sdk-python/blob/main/docs/core/logger.md
- Related issue Populate structured log data in custom object #305: Populate structured log data in custom object
- Related issue [Bug]: Structured logger adds unneccessary
\nto logging payloads #322: Structured logger adds unnecessary\nto logging payloads - Powertools console bypass: https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/logger/src/Logger.ts#L1102-L1105