-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: replace system fields value from seconds parameters #3217
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi, thank you for opening this issue. I believe this is intended, according to our documentation here (emphasis mine):
To avoid the behavior you're seeing, the logger.info('very important log key', { data }); which I confirmed produces: {
"level": "INFO",
"message": "very important log key",
"sampling_rate": 0,
"service": "production-server",
"timestamp": "2024-10-17T15:14:59.825Z",
"data": {
"timestamp": "one year ago",
"name": "user",
"message": "message from chat",
"level": "poweredUser",
"service": "internal chat"
}
} This is necessary because by default we merge each parameter with the JSON object of the log, so if your parameters have objects with duplicate keys they'll overwrite existing keys. I understand how the current wording doesn't explicitly state this, and I am sorry to hear it led to data loss. We'll consider improving the section, perhaps with a more explicit disclaimer. |
A warning in the documentation is very good, but trying to fix potential developer errors would be great. This is very unobvious behavior because it is not limited in any way with the help of TypeScript, and the developer constantly needs to remember this feature of the logger. Yesterday, one of our developers spent a lot of time because of this feature of the logger. It is very difficult for a developer who is using your logger for the first time to understand why this can be done
but that's not possible
|
In our case, the developer followed your recommendation completely, but got unexpected behavior.
|
This case is actually the next bullet point in that same section I linked above, and the fourth case in the code example right below it. |
Either way, I see where the confusion comes from and there is room for improvement. I don't think aliasing the fields is the right choice here, but I also don't have a better idea yet. Please allow me some time to discuss it with the team, and see what comes up. |
Hey @dreamorosi and @VladimirGorobetsWildix! I would like to share my impressions about this topic. In my opinion we should first distinguish between events fields and mandatory/default fields. These mandatory fields serve a purpose: they keep things organized and follow specific rules/protocol/rfc in that programming language. Let's look at the OTEL Data Model as an example. It has fields that must follow a certain pattern. These fields are part of how the Logger Data Model/Feature, not part of the actual event being logged. I also think that we need to look at this from the perspective of the tools that will retain/consume those logs. Let's imagine we ignore the RFC/Protocol and allow customers to override mandatory fields with any values they want. This could lead to several problems:
This could become a significant issue for everyone, as they may no longer trust their logs due to a lack of reliability. On the other hand, events often have custom fields that customers want to log and query later. This is a valid and common use case. However, if a customer wants to log the entire event with all its fields, regardless of what they are, this information should be included in the In Powertools Python you can do that using this code: from aws_lambda_powertools import Logger
logger = Logger()
event = {
"timestamp": 'one year ago',
"name": 'user',
"message": 'message from chat',
"level": 'admin',
"service": 'internal chat',
}
logger.info(msg=event) And then you'll have this output that can be used to query the information the customer needs:
Regarding to the possible solution:
I don't know if I would go down this path, we are changing the customer's information and this can create some questions and unwanted side effects. The solution I think of at the moment is that if we find any extra field that is a keyword, we issue a warning. I think this is good because of the following reasons: 1 - We do not change customer information What do you all think? Thanks |
I think the warning, as well as clearer documentation, would make the most sense. I agree that we shouldn't overwrite nor rename any field. |
Thanks @leandrodamascena
This is a very good point. Such non-obvious behavior can break the logic of log processing and we can lose an important part of the data. Still, I am of the opinion that secondary parameters have no right to change the values of system fields. |
I have started working on a fix for this bug, we're settling on the option of 1/ emitting a warning when we detect customers are trying to overwrite a reserved key, and 2/ dropping that key to preserve the original ones. I'm trying to minimize the overhead of this check by adding it in some targeted code paths, so it'll take a bit longer. I'll continue working on this into next week and hope to include the fix in the next release. |
Expected Behavior
System fields should not be replaced by values from additional parameters.
If duplicate fields occur, a prefix should be added for fields from additional objects.
For example
message -> _message
Current Behavior
Received result
First log is correct, but in the second log all system fields have been based on the fields of the second object.
This is a very non-obvious behavior that results in the loss of important logs and many hours of debugging and understanding the cause.
Code snippet
Steps to Reproduce
Possible Solution
If duplicate fields occur, a prefix should be added for fields from additional objects.
For example message -> _message
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
20.x
Packaging format used
npm
Execution logs
{"level":"INFO","message":"test message","sampling_rate":0,"service":"production-server","timestamp":"2024-10-17T14:40:49.209Z","user":"admin"}
{"level":"poweredUser","message":"message from chat","sampling_rate":0,"service":"internal chat","timestamp":"one year ago","name":"user"}
The text was updated successfully, but these errors were encountered: