Skip to content

Commit

Permalink
Merge pull request #17 from thcyron/fix-any
Browse files Browse the repository at this point in the history
Handle slog.Any as string otel attributes
  • Loading branch information
remychantenay authored Jul 9, 2024
2 parents 79b008e + 40f2258 commit a7d80f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion slog_otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (h OtelHandler) slogAttrToOtelAttr(attr slog.Attr, groupKeys ...string) att
case []bool:
return attribute.BoolSlice(key, v)
default:
return attribute.KeyValue{}
return attribute.String(key, fmt.Sprintf("%+v", v))
}
default:
return attribute.KeyValue{}
Expand Down
5 changes: 5 additions & 0 deletions slog_otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"log/slog"
"strings"
"testing"
Expand Down Expand Up @@ -127,6 +128,9 @@ func TestOtelHandler(t *testing.T) {
}, {
Key: "group_2.key_2",
Value: attribute.StringValue("value_2"),
}, {
Key: "err",
Value: attribute.StringValue("boom"),
}}

func() {
Expand All @@ -151,6 +155,7 @@ func TestOtelHandler(t *testing.T) {
"float64_slice", float64Slice,
"bool_slice", boolSlice,
"a_key", "a_value",
"err", errors.New("boom"),
group1,
group2,
)
Expand Down

0 comments on commit a7d80f5

Please sign in to comment.