Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GKE Emitter with Structured Tags #27

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading