You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What were you trying to accomplish?
The current 2.0.0-SNAPSHOT allows logging of reserved keys via structured arguments. This can lead to bugs where users accidentally log a key that is reserved by either the Logging module itself (e.g. message) or Powertools.
Given the following code, my expected behavior is that the message and service key appended via StructuredArguments are ignored and a user warning is logged stating that the appended keys are reserved keys by Powertools logging.
publicclassAppimplementsRequestHandler {
Loggerlog = LogManager.getLogger(App.class);
@LoggingpublicStringhandleRequest(finalObjectinput, finalContextcontext) {
log.info(
"My message.",
StructuredArguments.entry("message", "My duplicated message."),
StructuredArguments.entry("service", "My duplicated service."));
return"OK";
}
}
Expected output:
{
"level": "INFO",
"message": "My message.",
"cold_start": true,
"function_arn": "arn:aws:lambda:eu-west-1:<account id>:function:<function name>",
"function_memory_size": 512,
"function_name": "<function name>",
"function_request_id": "9b990378-33dc-470a-a4f2-5f69ccfca154",
"function_version": "$LATEST",
"service": "${env:POWERTOOLS_SERVICE_NAME}",
"timestamp": "2025-01-31T10:54:23.730Z",
"xray_trace_id": "1-679cabdd-0676a40a4205208f06b16cbf"
}
{
"level": "WARN",
"message": "Detected logging of reserved keys 'message', 'service' as structured arguments. Structured arguments with reserved keys will be ignored. More information at <link to docs>.",
"cold_start": true,
"function_arn": "arn:aws:lambda:eu-west-1:<account id>:function:<function name>",
"function_memory_size": 512,
"function_name": "<function name>",
"function_request_id": "9b990378-33dc-470a-a4f2-5f69ccfca154",
"function_version": "$LATEST",
"service": "${env:POWERTOOLS_SERVICE_NAME}",
"timestamp": "2025-01-31T10:54:23.730Z",
"xray_trace_id": "1-679cabdd-0676a40a4205208f06b16cbf"
}
Current Behavior
The current behavior outputs the key twice to STDOUT. In CloudWatch, it ignores the first key which will lead to logging of the structured argument only.
Output to STDOUT (second message and service key comes from StructuredArguments):
What were you trying to accomplish?
The current
2.0.0-SNAPSHOT
allows logging of reserved keys via structured arguments. This can lead to bugs where users accidentally log a key that is reserved by either the Logging module itself (e.g.message
) or Powertools.Examples below are using:
Expected Behavior
Given the following code, my expected behavior is that the
message
andservice
key appended viaStructuredArguments
are ignored and a user warning is logged stating that the appended keys are reserved keys by Powertools logging.Expected output:
Current Behavior
The current behavior outputs the key twice to STDOUT. In CloudWatch, it ignores the first key which will lead to logging of the structured argument only.
Output to STDOUT (second
message
andservice
key comes fromStructuredArguments
):Output in CloudWatch (initial
message
andservice
keys are shadowed by the provided structured arguments without warning):Environment
2.0.0-SNAPSHOT
/ Java11Same behavior in
1.18.0
Same behavior is observed for the current
v1
version1.18.0
.The text was updated successfully, but these errors were encountered: