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
Currently, when M.Format or MarshalLogObject are called, they result in the mutation of the receiver. This leads to the unexpected mutation of values when printing or logging mapstr.M.
This is demonstrated by running the following program.
The underlying cause of this is that mapstr.M.Clone, while claiming to deep copy the receiver, does not when it comes to slices or array; only shallow copies are made when any value that is not assignable to a mapstr.M is encountered.
The text was updated successfully, but these errors were encountered:
This seems important or severe because it has the potential to "corrupt" data being sent to Elasticsearch, particularly when debug is enabled. I did a very narrow, non-exhaustive search in Beats, and there are cases where this could occur such as
My immediate concern is to ensure data cannot be mutated as a side-effect of logging. Secondarily, I think separation of concerns should be reconsidered for mapstr.M. I don't think a map data structure should be concerned with logging redaction. That IMO, most likely, should be a concern of the logger.
For redaction, I would suggest that one of the shim layers in logp makes a conditional call based on whether the value implements a (bikeshed) Redact() any/Replace() any method. This method would return a log-safe version of the value. Having this be an interface would allow any value to be redacted in logs by providing a wrapper utility type that would perform redaction on the value that it holds. Notably, mapstr.Mshould not implement this by default since a global logger cannot know the significance of fields purely based on the name of the field.
Redaction makes sense to me in the logger, see elastic/elastic-agent#5675 for a place where we'd immediately use this. I think the key would be making it impossible to forget to redact, without mandatory redaction imposing significant performance overhead.
Currently, when
M.Format
orMarshalLogObject
are called, they result in the mutation of the receiver. This leads to the unexpected mutation of values when printing or loggingmapstr.M
.This is demonstrated by running the following program.
output:
https://go.dev/play/p/rviU45kYeOk
The underlying cause of this is that
mapstr.M.Clone
, while claiming to deep copy the receiver, does not when it comes to slices or array; only shallow copies are made when any value that is not assignable to amapstr.M
is encountered.The text was updated successfully, but these errors were encountered: