Skip to content
Open
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
6 changes: 6 additions & 0 deletions interceptors/logging/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (c *reporter) PostMsgSend(payload any, err error, duration time.Duration) {
if !logStartCall && !logPayloadSend {
return
}
if errors.Is(err, io.EOF) {
err = nil
}

logLvl := c.opts.levelFunc(c.opts.codeFunc(err))
fields := c.fields.WithUnique(ExtractFields(c.ctx))
Expand Down Expand Up @@ -105,6 +108,9 @@ func (c *reporter) PostMsgReceive(payload any, err error, duration time.Duration
if !logStartCall && !logPayloadReceived {
return
}
if errors.Is(err, io.EOF) {
err = nil
}

logLvl := c.opts.levelFunc(c.opts.codeFunc(err))
fields := c.fields.WithUnique(ExtractFields(c.ctx))
Expand Down
21 changes: 21 additions & 0 deletions interceptors/logging/interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,27 @@ func (s *loggingClientServerSuite) TestPingList() {
AssertFieldNotEmpty(s.T(), "grpc.time_ms").AssertNoMoreTags(s.T())
}

func (s *loggingClientServerSuite) TestPingStream_EOFIsNotLoggedAsError() {
stream, err := s.Client.PingStream(s.SimpleCtx())
s.Require().NoError(err, "should not fail on establishing the stream")
s.Require().NoError(stream.CloseSend())
_, err = stream.Recv()
s.Require().ErrorIs(err, io.EOF)

lines := s.logger.o.Lines()
sort.Sort(lines)
s.Require().Len(lines, 4)

s.Assert().Equal("finished call", lines[0].msg)
s.Assert().Equal("started call", lines[1].msg)
s.Assert().Equal("finished call", lines[2].msg)
s.Assert().Equal("started call", lines[3].msg)
for _, line := range lines {
s.Assert().Equal(logging.LevelDebug, line.lvl)
s.Assert().NotContains(line.fields, "grpc.error")
}
}

func (s *loggingClientServerSuite) TestPingError_WithCustomLevels() {
for _, tcase := range []struct {
code codes.Code
Expand Down
Loading