Repository navigation
promslog: don't rename reserved keys inside groups - #1021
Open
vignesh2027 wants to merge 1 commit into
Open
vignesh2027 wants to merge 1 commit into
vignesh2027 wants to merge 1 commit into
Conversation
The ReplaceAttr functions rename attributes whose key matches a built-in
key (time, level, source, and ts and caller for the go-kit style) to
logged_<key>, so they don't collide with the top-level built-in
attributes. They ignored the groups argument, so the same rename was
applied to attributes nested in a group, for example
slog.Group("req", "level", "high") was written as req.logged_level=high.
A grouped attribute can't collide with a top-level key, so leave it
untouched. Built-in attributes are always passed with no groups.
Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both ReplaceAttr functions in promslog rename an attribute whose key is a built-in key (
time,level,source, plustsandcallerin the go-kit style) tologged_<key>, so it can't collide with the top-level attribute of the same name. They ignore thegroupsargument, so attributes nested in a group get renamed too, even though they can't collide with anything:The same happens with
logger.WithGroup("sub").slog passes the built-in attributes with an empty
groupsslice, so the fix skips the reserved key handling whengroupsis not empty. Top-level renaming and the time.Duration formatting are unchanged.Tests: added
TestReservedKeysInGroup, which covers both log styles withslog.GroupandWithGroup, and checks that the built-in keys are still written. It fails on main withreq.logged_level=groupedin the output and passes with the change.TestReservedKeysstill passes.