Skip to content

Commit 5ecb4b6

Browse files
authored
fix: parent groups appended to all attributes #19 (#20)
1 parent 88a8c91 commit 5ecb4b6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

otelslog/conv.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func otelAttribute(attr slog.Attr) []attribute.KeyValue {
3939
group := attr.Value.Group()
4040
var result []attribute.KeyValue
4141
for _, v := range group {
42+
v.Key = attr.Key + "." + v.Key
4243
result = append(result, otelAttribute(v)...)
4344
}
4445
return result

otelslog/otel_handler_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ func newResource() *resource.Resource {
2727
}
2828

2929
func doSomething(ctx context.Context) {
30-
slog.InfoContext(ctx, "hello slog", slog.String("myKey", "myValue"))
30+
slog.InfoContext(ctx, "hello slog", slog.String("myKey", "myValue"),
31+
slog.Group("myGroup", slog.String("groupKey", "groupValue")))
3132
}
3233

3334
func TestNewOtelHandler(t *testing.T) {
@@ -60,5 +61,5 @@ func TestNewOtelHandler(t *testing.T) {
6061
actual := buf.String()
6162

6263
assert.Contains(t, actual, "INFO hello slog [scopeInfo: github.com/agoda-com/otelslog:0.0.1] {host.name=")
63-
assert.Contains(t, actual, "service.name=otelslog-example, service.version=1.0.0, first=value1, group1.second=value2, group1.group2.myKey=myValue}")
64+
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}")
6465
}

0 commit comments

Comments
 (0)