Skip to content

Commit

Permalink
fix: parent groups appended to all attributes #19 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
scwagner authored May 30, 2024
1 parent 88a8c91 commit 5ecb4b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions otelslog/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func otelAttribute(attr slog.Attr) []attribute.KeyValue {
group := attr.Value.Group()
var result []attribute.KeyValue
for _, v := range group {
v.Key = attr.Key + "." + v.Key
result = append(result, otelAttribute(v)...)
}
return result
Expand Down
5 changes: 3 additions & 2 deletions otelslog/otel_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func newResource() *resource.Resource {
}

func doSomething(ctx context.Context) {
slog.InfoContext(ctx, "hello slog", slog.String("myKey", "myValue"))
slog.InfoContext(ctx, "hello slog", slog.String("myKey", "myValue"),
slog.Group("myGroup", slog.String("groupKey", "groupValue")))
}

func TestNewOtelHandler(t *testing.T) {
Expand Down Expand Up @@ -60,5 +61,5 @@ func TestNewOtelHandler(t *testing.T) {
actual := buf.String()

assert.Contains(t, actual, "INFO hello slog [scopeInfo: github.com/agoda-com/otelslog:0.0.1] {host.name=")
assert.Contains(t, actual, "service.name=otelslog-example, service.version=1.0.0, first=value1, group1.second=value2, group1.group2.myKey=myValue}")
assert.Contains(t, actual, "service.name=otelslog-example, service.version=1.0.0, first=value1, group1.second=value2, group1.group2.myKey=myValue, group1.group2.myGroup.groupKey=groupValue}")
}

0 comments on commit 5ecb4b6

Please sign in to comment.