Skip to content

Commit

Permalink
otelslog: Handle nil attribute value properly
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Oct 14, 2024
1 parent d6305c0 commit 7947e54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bridges/otelslog/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ func (b *kvBuffer) AddAttr(attr slog.Attr) bool {
func convertValue(v slog.Value) log.Value {
switch v.Kind() {
case slog.KindAny:
if v.Any() == nil {
return log.Value{}
}
return log.StringValue(fmt.Sprintf("%+v", v.Any()))
case slog.KindBool:
return log.BoolValue(v.Bool())
Expand Down
2 changes: 2 additions & 0 deletions bridges/otelslog/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func TestSLogHandler(t *testing.T) {
"string", "str",
"time", now,
"uint64", uint64(3),
"nil", nil,
// KindGroup and KindLogValuer are left for slogtest.TestHandler.
)
},
Expand All @@ -254,6 +255,7 @@ func TestSLogHandler(t *testing.T) {
hasAttr("string", "str"),
hasAttr("time", now.UnixNano()),
hasAttr("uint64", int64(3)),
hasAttr("nil", nil),
}},
},
{
Expand Down

0 comments on commit 7947e54

Please sign in to comment.