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

adds fields from durationFieldFunc to request/response log entries #670

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
4 changes: 4 additions & 0 deletions interceptors/logging/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (c *reporter) PostMsgSend(payload any, err error, duration time.Duration) {
}

fields = fields.AppendUnique(Fields{"grpc.send.duration", duration.String(), "grpc.request.content", p})
fields = fields.AppendUnique(c.opts.durationFieldFunc(duration))
c.logger.Log(c.ctx, logLvl, "request sent", fields...)
} else {
p, ok := payload.(proto.Message)
Expand All @@ -85,6 +86,7 @@ func (c *reporter) PostMsgSend(payload any, err error, duration time.Duration) {
}

fields = fields.AppendUnique(Fields{"grpc.send.duration", duration.String(), "grpc.response.content", p})
fields = fields.AppendUnique(c.opts.durationFieldFunc(duration))
c.logger.Log(c.ctx, logLvl, "response sent", fields...)
}
}
Expand Down Expand Up @@ -116,6 +118,7 @@ func (c *reporter) PostMsgReceive(payload any, err error, duration time.Duration
}

fields = fields.AppendUnique(Fields{"grpc.recv.duration", duration.String(), "grpc.request.content", p})
fields = fields.AppendUnique(c.opts.durationFieldFunc(duration))
c.logger.Log(c.ctx, logLvl, "request received", fields...)
} else {
p, ok := payload.(proto.Message)
Expand All @@ -130,6 +133,7 @@ func (c *reporter) PostMsgReceive(payload any, err error, duration time.Duration
}

fields = fields.AppendUnique(Fields{"grpc.recv.duration", duration.String(), "grpc.response.content", p})
fields = fields.AppendUnique(c.opts.durationFieldFunc(duration))
c.logger.Log(c.ctx, logLvl, "response received", fields...)
}
}
Expand Down
5 changes: 5 additions & 0 deletions interceptors/logging/interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func (s *loggingPayloadSuite) TestPingError_LogsOnlyRequestsOnError() {

clientRequestFields.AssertFieldNotEmpty(s.T(), "grpc.start_time").
AssertFieldNotEmpty(s.T(), "grpc.send.duration").
AssertFieldNotEmpty(s.T(), "grpc.time_ms").
AssertField(s.T(), "grpc.request.content", `{"value":"something","errorCodeReturned":4}`).
AssertFieldNotEmpty(s.T(), "grpc.request.deadline").AssertNoMoreTags(s.T())
}
Expand Down Expand Up @@ -580,6 +581,7 @@ func (s *loggingPayloadSuite) assertPayloadLogLinesForMessage(lines LogLines, me
clientRequestFields := assertStandardFields(s.T(), logging.KindClientFieldValue, clientRequestLogLine.fields, method, typ)
clientRequestFields.AssertFieldNotEmpty(s.T(), "grpc.start_time").
AssertFieldNotEmpty(s.T(), "grpc.send.duration").
AssertFieldNotEmpty(s.T(), "grpc.time_ms").
AssertField(s.T(), "grpc.request.content", `{"value":"something","sleepTimeMs":9999}`).
AssertFieldNotEmpty(s.T(), "grpc.request.deadline").AssertNoMoreTags(s.T())
}
Expand All @@ -591,6 +593,7 @@ func (s *loggingPayloadSuite) assertPayloadLogLinesForMessage(lines LogLines, me
clientResponseFields := assertStandardFields(s.T(), logging.KindClientFieldValue, clientResponseLogLine.fields, method, typ)
clientResponseFields = clientResponseFields.AssertFieldNotEmpty(s.T(), "grpc.start_time").
AssertFieldNotEmpty(s.T(), "grpc.recv.duration").
AssertFieldNotEmpty(s.T(), "grpc.time_ms").
AssertFieldNotEmpty(s.T(), "grpc.request.deadline")
if i-curr == 0 {
clientResponseFields = clientResponseFields.AssertField(s.T(), "grpc.response.content", `{"value":"something"}`)
Expand All @@ -609,6 +612,7 @@ func (s *loggingPayloadSuite) assertPayloadLogLinesForMessage(lines LogLines, me
AssertFieldNotEmpty(s.T(), "grpc.start_time").
AssertFieldNotEmpty(s.T(), "grpc.recv.duration").
AssertFieldNotEmpty(s.T(), "grpc.request.deadline").
AssertFieldNotEmpty(s.T(), "grpc.time_ms").
AssertField(s.T(), "grpc.request.content", `{"value":"something","sleepTimeMs":9999}`).AssertNoMoreTags(s.T())
}
curr += repetitions
Expand All @@ -620,6 +624,7 @@ func (s *loggingPayloadSuite) assertPayloadLogLinesForMessage(lines LogLines, me
serverResponseFields = serverResponseFields.AssertFieldNotEmpty(s.T(), "peer.address").
AssertFieldNotEmpty(s.T(), "grpc.start_time").
AssertFieldNotEmpty(s.T(), "grpc.send.duration").
AssertFieldNotEmpty(s.T(), "grpc.time_ms").
AssertFieldNotEmpty(s.T(), "grpc.request.deadline")
if i-curr == 0 {
serverResponseFields = serverResponseFields.AssertField(s.T(), "grpc.response.content", `{"value":"something"}`)
Expand Down
Loading