Skip to content

Commit

Permalink
Improve logs (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmsilva-wls authored Dec 5, 2022
1 parent bfc70e6 commit 5fdfd5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ func (a *App) metricsReporterInterceptor(
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (interface{}, error) {
l := a.log.WithField("route", info.FullMethod)

events := []*pb.Event{}
retry := "0"
switch t := req.(type) {
Expand All @@ -167,8 +165,13 @@ func (a *App) metricsReporterInterceptor(
events = append(events, req.(*pb.SendEventsRequest).Events...)
retry = fmt.Sprintf("%d", req.(*pb.SendEventsRequest).Retry)
default:
l.Infof("Unexpected request type %T", t)
a.log.WithField("route", info.FullMethod).Infof("Unexpected request type %T", t)
}

topic := events[0].Topic
l := a.log.
WithField("route", info.FullMethod).
WithField("topic", topic)

defer func(startTime time.Time) {
elapsedTime := float64(time.Since(startTime).Nanoseconds() / (1000 * 1000))
Expand Down
5 changes: 4 additions & 1 deletion sender/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func (k *KafkaSender) SendEvents(
j := i
go func() {
if err := k.SendEvent(ctx, events[j]); err != nil {
k.logger.WithError(err).Error("failed to send event to kafka")
k.logger.
WithError(err).
WithField("topic", events[j].Topic).
Error("failed to send event to kafka")
failureIndexes = append(failureIndexes, int64(j))
}
wg.Done()
Expand Down

0 comments on commit 5fdfd5f

Please sign in to comment.