Skip to content

Commit

Permalink
Fix GKE Emitter with Structured Tags
Browse files Browse the repository at this point in the history
Fix a bug where only the first structured tag would be emitted in the
gke emitter.
  • Loading branch information
sergiosalvatore committed Aug 19, 2024
1 parent 92e1b42 commit c88860b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion emitter/gkelog/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func Emitter(opt ...Option) alog.Emitter {
}
for i, sTag := range e.STags {
_, asStringTag := tagPositions[sTag.Key] // has this already been used as a string tag?
if tagPositions[sTag.Key] != i || asStringTag || reservedKeys[sTag.Key] {
if sTagPositions[sTag.Key] != i || asStringTag || reservedKeys[sTag.Key] {
continue
}

Expand Down
14 changes: 12 additions & 2 deletions emitter/gkelog/emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,21 @@ func TestLabels(t *testing.T) {
X: 1,
},
}

structured2 := alog.STag{
Key: "structured-again",
Val: struct {
Y string `json:"val"`
}{
Y: "foo",
},
}

ctx = alog.AddTags(ctx, "allthese", "tags", "andanother", "tag")
ctx = alog.AddStructuredTags(ctx, structured)
ctx = alog.AddStructuredTags(ctx, structured, structured2)
l.Print(ctx, "test")

want := `{"time":"0001-01-01T00:00:00Z", "allthese":"tags", "andanother":"tag", "structured":{"x":1}, "message":"test"}` + "\n"
want := `{"time":"0001-01-01T00:00:00Z", "allthese":"tags", "andanother":"tag", "structured":{"x":1}, "structured-again":{"val":"foo"}, "message":"test"}` + "\n"
got := b.String()
if got != want {
t.Errorf("got:\n%s\nwant:\n%s", got, want)
Expand Down

0 comments on commit c88860b

Please sign in to comment.