Skip to content

Commit

Permalink
otelslog: Transform slices and other raw types
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Oct 15, 2024
1 parent 601f98b commit e20c2d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 1 addition & 4 deletions bridges/otelslog/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,7 @@ func (b *kvBuffer) AddAttr(attr slog.Attr) bool {
func convert(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()))
return convertValue(v.Any())
case slog.KindBool:
return log.BoolValue(v.Bool())
case slog.KindDuration:
Expand Down
4 changes: 3 additions & 1 deletion bridges/otelslog/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func value2Result(v log.Value) any {
case log.KindBytes:
return v.AsBytes()
case log.KindSlice:
return v.AsSlice()
return v
case log.KindMap:
m := make(map[string]any)
for _, val := range v.AsMap() {
Expand Down Expand Up @@ -241,6 +241,7 @@ func TestSLogHandler(t *testing.T) {
"time", now,
"uint64", uint64(3),
"nil", nil,
"slice", []string{"foo", "bar"},
// KindGroup and KindLogValuer are left for slogtest.TestHandler.
)
},
Expand All @@ -256,6 +257,7 @@ func TestSLogHandler(t *testing.T) {
hasAttr("time", now.UnixNano()),
hasAttr("uint64", int64(3)),
hasAttr("nil", nil),
hasAttr("slice", log.SliceValue(log.StringValue("foo"), log.StringValue("bar"))),
}},
},
{
Expand Down

0 comments on commit e20c2d5

Please sign in to comment.