-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
.With() function repeating keys/values #622
Comments
This is as designed, and is documented in Supporting a last-writer-wins policy as you suggest is remarkably difficult in zap (and similar projects) - zap is fast because it encodes fields as they're added, without maintaining some intermediate representation (commonly In short, this is functioning as designed. If you're interested in a fairly complex PR, I can guide you through how we might implement this feature and benchmark the performance impact. |
Just a note: This seems to be an issue when sending said logs to GCP's stackdriver. {
"trace": "foo",
"trace": "foo"
} will be presented in stackdriver as {
"trace": "foofoo"
} |
Huh! I'm a little surprised by this, but perhaps Google's also trying to avoid dropping the duplicate data. I'm no longer at Uber, so the current maintainers have the final say on whether to make any changes to the current duplicate-handling code. If this is particularly inconvenient for you, you can wrap zap's JSON encoder and fix it yourself. To keep performance reasonably good, you could use a Bloom filter:
That would keep serialization reasonably fast and zero-allocation when there are no duplicates. I haven't thought through how you'd handle duplicates in nested objects (created by |
According to the RFC:
zap is relying on readers implementing a "last one wins" approach, but that is not required by the spec. You are right that SHOULD is not MUST, so it's not wrong to write JSON with duplicates - it's just not guaranteed to be interoperable. |
Using
.With()
function it's repeating the same key/value for everyWith
call. Should it overwrite the previous values or have a function to remove specific keys/values previously set?The text was updated successfully, but these errors were encountered: