aws / aws/aws-durable-execution-sdk-js
[Feature]: Native AWS Lambda Powertools for TypeScript integration
- Dominant language
- TypeScript
- Stars
- 84
- Forks
- 28
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 43
Description
### Feature Request
Native integration with [AWS Lambda Powertools for TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/) Logger, similar to how the [Python Durable SDK supports Powertools](https://github.com/aws/aws-durable-execution-sdk-python/blob/main/docs/core/logger.md).
### Problem
When using Powertools Logger as a `customLogger` via `context.configureLogger()`, the logs get **double-wrapped** in CloudWatch because:
1. Durable functions **require** `LogFormat: JSON` in the Lambda config
2. Lambda's `LogFormat: JSON` patches the global `console` object to wrap output in `{"timestamp", "level", "requestId", "message"}`
3. Powertools Logger uses the global `console.info()` to output its own structured JSON
4. Lambda catches that and stringifies Powertools' JSON into the `message` field
**Result — double-wrapped JSON:**
```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](https://github.com/aws/aws-durable-execution-sdk-js/blob/main/packages/aws-durable-execution-sdk-js/src/utils/logger/default-logger.ts) and [Powertools itself uses](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/logger/src/Logger.ts#L1102-L1105)):
```typescript
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:
```typescript
const handler = async (event: MyEvent, context: DurableContext) => {
context.configureLogger({ customLogger: logger });
context.logger.info({ message: 'workflow-started' });
};
export const myFunction = withDurableExecution(handler);
```
**Result — clean Powertools output:**
```json
{
"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
1. **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 via `append_keys()`. The JS SDK should have parity.
2. **Handle the console patching conflict** — When Powertools is detected as the `customLogger`, the SDK should automatically handle the `LogFormat: JSON` console patching conflict so users don't need the workaround above.
3. **Inject durable metadata into Powertools structured logs** — Use Powertools' `appendKeys()` method to inject durable execution context (like `executionArn`, `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 #305: Populate structured log data in custom object
- Related issue #322: Structured logger adds unnecessary `\n` to logging payloads
- Powertools console bypass: https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/logger/src/Logger.ts#L1102-L1105
Contributor guide
Research direction
Start at the JavaScript SDK's context.configureLogger() customLogger path and compare it with the referenced Python Powertools integration. Review the referenced DefaultLogger and Powertools Logger console handling, then define how appendKeys() should receive durable metadata without double-wrapped output. Done means native Powertools support covers metadata injection and the Lambda LogFormat:JSON conflict.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, typescript
- Domain
- backend, cloud, observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100