From 408c81330959af872b106acaca9618b77953719a Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Wed, 13 Jul 2022 11:32:40 -0400 Subject: [PATCH] fix logging --- internal/worker/notifications.go | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index 275095e..0392554 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -144,7 +144,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { } }(id) - nc.logger.Debug("starting job", zap.String("account#account_id", id)) + nc.logger.Debug("starting job", zap.String("account#reddit_account_id", id)) defer func() { _ = delivery.Ack() }() @@ -152,7 +152,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { account, err := nc.accountRepo.GetByRedditID(nc, id) if err != nil { - nc.logger.Error("failed to fetch account from database", zap.Error(err), zap.String("account#account_id", id)) + nc.logger.Error("failed to fetch account from database", zap.Error(err), zap.String("account#reddit_account_id", id)) return } @@ -165,7 +165,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { if err = nc.accountRepo.Update(nc, acc); err != nil { nc.logger.Error("failed to update account", zap.Error(err), - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) } @@ -174,7 +174,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { rac := nc.reddit.NewAuthenticatedClient(account.AccountID, account.RefreshToken, account.AccessToken) if account.TokenExpiresAt.Before(now.Add(5 * time.Minute)) { nc.logger.Debug("refreshing reddit token", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) @@ -183,7 +183,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { if err != reddit.ErrOauthRevoked { nc.logger.Error("failed to refresh reddit tokens", zap.Error(err), - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) return @@ -193,7 +193,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { if err != nil { nc.logger.Error("failed to remove revoked account", zap.Error(err), - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) } @@ -217,7 +217,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { _ = nc.statsd.Histogram("apollo.queue.delay", float64(latency.Milliseconds()), []string{}, rate) } - nc.logger.Debug("fetching message inbox", zap.String("account#account_id", id), zap.String("account#username", account.NormalizedUsername())) + nc.logger.Debug("fetching message inbox", zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername())) opts := []reddit.RequestOption{reddit.WithQuery("limit", "10")} if account.LastMessageID != "" { @@ -233,19 +233,19 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { if err = nc.deleteAccount(account); err != nil { nc.logger.Error("failed to remove revoked account", zap.Error(err), - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) } else { nc.logger.Info("removed revoked account", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) } default: nc.logger.Error("failed to fetch message inbox", zap.Error(err), - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) } @@ -255,14 +255,14 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { // Figure out where we stand if msgs.Count == 0 { nc.logger.Debug("no new messages, bailing early", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) return } nc.logger.Debug("fetched messages", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), zap.Int("count", msgs.Count), ) @@ -277,7 +277,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { // Let's populate this with the latest message so we don't flood users with stuff if newAccount { nc.logger.Debug("populating first message id to prevent spamming", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) return @@ -287,7 +287,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { if err != nil { nc.logger.Error("failed to fetch account devices", zap.Error(err), - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) return @@ -295,7 +295,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { if len(devices) == 0 { nc.logger.Debug("no notifiable devices, bailing early", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) return @@ -325,7 +325,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { _ = nc.statsd.Incr("apns.notification.errors", []string{}, 1) nc.logger.Error("failed to send notification", zap.Error(err), - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), zap.String("device#token", device.APNSToken), ) @@ -335,7 +335,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { } else if !res.Sent() { _ = nc.statsd.Incr("apns.notification.errors", []string{}, 1) nc.logger.Error("notification not sent", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), zap.String("device#token", device.APNSToken), zap.Int("response#status", res.StatusCode), @@ -347,7 +347,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { } else { _ = nc.statsd.Incr("apns.notification.sent", []string{}, 1) nc.logger.Info("sent notification", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), zap.String("device#token", device.APNSToken), ) @@ -359,7 +359,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { _ = nc.statsd.SimpleEvent(ev, "") nc.logger.Debug("finishing job", - zap.String("account#account_id", id), + zap.String("account#reddit_account_id", id), zap.String("account#username", account.NormalizedUsername()), ) }