-
Notifications
You must be signed in to change notification settings - Fork 176
Description
Expected Behavior
When creating a child logger I expect persistentKeys from the parent to be merged into the child's.
Current Behavior
When calling logger.createChild with the persistentKeys object, existing persistent keys on the parent are completely cleared out instead of merged together.
Code snippet
const logger = new Logger({
persistentKeys: {
foo: 'hello',
overridable: 1,
},
})
logger.appendKeys({
resettableKey: 'some-id',
})
logger.appendPersistentKeys({
dynamic: 'stays',
})
const child = logger.createChild({
persistentKeys: {
bar: 'world',
overridable: 2,
},
})
child.info('Log Message')
child.resetKeys()
child.info('Log Message 2')Expected Output:
{
"level": "INFO",
"message": "Log Message",
"timestamp": "2025-11-06T18:54:49.202Z",
"service": "service_undefined",
"sampling_rate": 0,
"foo": "hello",
"overridable": 2,
"dynamic": "stays",
"bar": "world",
"resettableKey": "some-id"
}
{
"level": "INFO",
"message": "Log Message 2",
"timestamp": "2025-11-06T18:54:49.204Z",
"service": "service_undefined",
"sampling_rate": 0,
"foo": "hello",
"overridable": 2,
"dynamic": "stays",
"bar": "world"
}Current Output:
{
"level": "INFO",
"message": "Log Message",
"timestamp": "2025-11-06T18:57:06.315Z",
"service": "service_undefined",
"sampling_rate": 0,
"bar": "world",
"overridable": 2,
"resettableKey": "some-id"
}
{
"level": "INFO",
"message": "Log Message 2",
"timestamp": "2025-11-06T18:57:06.315Z",
"service": "service_undefined",
"sampling_rate": 0,
"bar": "world",
"overridable": 2
}Steps to Reproduce
- Create file with code snippet from above
- Run the code and see the console output
Possible Solution
I believe this is due to this line where creating a child relies on setting the deprecated persistentLogAttributes instead of the newer persistentKeys attribute. Which is ignored during instantiation if both are used seen here. This usage of the deprecated api also contributes to why when creating a child and setting persistentKeys on it, the
Both persistentLogAttributes and persistentKeys options were provided.
warning is displayed regardless of callers actually using that deprecated attribute or not. Related issue
I can help contribute this if it is a desired fix
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
Type
Projects
Status