Skip to content

fix(slog): keep attrs with an empty key and non-zero value - #847

Open
CJstate wants to merge 1 commit into
rs:masterfrom
CJstate:fix/slog-empty-key-attr
Open

CJstate wants to merge 1 commit into
rs:masterfrom
CJstate:fix/slog-empty-key-attr

Conversation

@CJstate

@CJstate CJstate commented Dec 1, 2026

Copy link
Copy Markdown

Per slog.Handler semantics, only a zero slog.Attr should be dropped. SlogHandler checked only attr.Key == "", so any attribute with an empty key but a non-zero value (e.g. logger.Info("msg", "", "v")) was silently dropped.

This changes the check to attr.Equal(slog.Attr{}). Two regression tests cover the empty-key non-zero attr and the zero-attr case. go test ./... passes.

Per slog.Handler semantics, only a zero Attr is dropped. The handler currently
checked only attr.Key == "", so any attribute with an empty key
but a non-zero value (e.g. logger.Info("msg", "", "v")) was silently
dropped. Fix by dropping only attr.Equal(slog.Attr{}). Two regression
tests cover the empty-key non-zero attr and the zero-attr case.

Signed-off-by: CJstate <142857225+CJstate@users.noreply.github.com>

rs commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Could you add a regression for an empty-key nonzero attribute under WithGroup, as well as an empty-key group that should inline its children? The root-level fix looks useful, but the current prefix joining can turn an empty leaf key into the group key itself. That case would also help us decide how to land this alongside the broader slog handler work.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants