fix logging

This commit is contained in:
Andre Medeiros 2022-07-13 11:32:40 -04:00
parent d1d00d158d
commit 408c813309

View file

@ -144,7 +144,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
} }
}(id) }(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() }() defer func() { _ = delivery.Ack() }()
@ -152,7 +152,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
account, err := nc.accountRepo.GetByRedditID(nc, id) account, err := nc.accountRepo.GetByRedditID(nc, id)
if err != nil { 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 return
} }
@ -165,7 +165,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
if err = nc.accountRepo.Update(nc, acc); err != nil { if err = nc.accountRepo.Update(nc, acc); err != nil {
nc.logger.Error("failed to update account", nc.logger.Error("failed to update account",
zap.Error(err), zap.Error(err),
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), 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) rac := nc.reddit.NewAuthenticatedClient(account.AccountID, account.RefreshToken, account.AccessToken)
if account.TokenExpiresAt.Before(now.Add(5 * time.Minute)) { if account.TokenExpiresAt.Before(now.Add(5 * time.Minute)) {
nc.logger.Debug("refreshing reddit token", 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()), zap.String("account#username", account.NormalizedUsername()),
) )
@ -183,7 +183,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
if err != reddit.ErrOauthRevoked { if err != reddit.ErrOauthRevoked {
nc.logger.Error("failed to refresh reddit tokens", nc.logger.Error("failed to refresh reddit tokens",
zap.Error(err), zap.Error(err),
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), zap.String("account#username", account.NormalizedUsername()),
) )
return return
@ -193,7 +193,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
if err != nil { if err != nil {
nc.logger.Error("failed to remove revoked account", nc.logger.Error("failed to remove revoked account",
zap.Error(err), zap.Error(err),
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), 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.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")} opts := []reddit.RequestOption{reddit.WithQuery("limit", "10")}
if account.LastMessageID != "" { if account.LastMessageID != "" {
@ -233,19 +233,19 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
if err = nc.deleteAccount(account); err != nil { if err = nc.deleteAccount(account); err != nil {
nc.logger.Error("failed to remove revoked account", nc.logger.Error("failed to remove revoked account",
zap.Error(err), zap.Error(err),
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), zap.String("account#username", account.NormalizedUsername()),
) )
} else { } else {
nc.logger.Info("removed revoked account", 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()), zap.String("account#username", account.NormalizedUsername()),
) )
} }
default: default:
nc.logger.Error("failed to fetch message inbox", nc.logger.Error("failed to fetch message inbox",
zap.Error(err), zap.Error(err),
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), zap.String("account#username", account.NormalizedUsername()),
) )
} }
@ -255,14 +255,14 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
// Figure out where we stand // Figure out where we stand
if msgs.Count == 0 { if msgs.Count == 0 {
nc.logger.Debug("no new messages, bailing early", 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()), zap.String("account#username", account.NormalizedUsername()),
) )
return return
} }
nc.logger.Debug("fetched messages", 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.String("account#username", account.NormalizedUsername()),
zap.Int("count", msgs.Count), 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 // Let's populate this with the latest message so we don't flood users with stuff
if newAccount { if newAccount {
nc.logger.Debug("populating first message id to prevent spamming", 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()), zap.String("account#username", account.NormalizedUsername()),
) )
return return
@ -287,7 +287,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
if err != nil { if err != nil {
nc.logger.Error("failed to fetch account devices", nc.logger.Error("failed to fetch account devices",
zap.Error(err), zap.Error(err),
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), zap.String("account#username", account.NormalizedUsername()),
) )
return return
@ -295,7 +295,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
if len(devices) == 0 { if len(devices) == 0 {
nc.logger.Debug("no notifiable devices, bailing early", 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()), zap.String("account#username", account.NormalizedUsername()),
) )
return return
@ -325,7 +325,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
_ = nc.statsd.Incr("apns.notification.errors", []string{}, 1) _ = nc.statsd.Incr("apns.notification.errors", []string{}, 1)
nc.logger.Error("failed to send notification", nc.logger.Error("failed to send notification",
zap.Error(err), zap.Error(err),
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), zap.String("account#username", account.NormalizedUsername()),
zap.String("device#token", device.APNSToken), zap.String("device#token", device.APNSToken),
) )
@ -335,7 +335,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
} else if !res.Sent() { } else if !res.Sent() {
_ = nc.statsd.Incr("apns.notification.errors", []string{}, 1) _ = nc.statsd.Incr("apns.notification.errors", []string{}, 1)
nc.logger.Error("notification not sent", 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("account#username", account.NormalizedUsername()),
zap.String("device#token", device.APNSToken), zap.String("device#token", device.APNSToken),
zap.Int("response#status", res.StatusCode), zap.Int("response#status", res.StatusCode),
@ -347,7 +347,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
} else { } else {
_ = nc.statsd.Incr("apns.notification.sent", []string{}, 1) _ = nc.statsd.Incr("apns.notification.sent", []string{}, 1)
nc.logger.Info("sent notification", 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("account#username", account.NormalizedUsername()),
zap.String("device#token", device.APNSToken), zap.String("device#token", device.APNSToken),
) )
@ -359,7 +359,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
_ = nc.statsd.SimpleEvent(ev, "") _ = nc.statsd.SimpleEvent(ev, "")
nc.logger.Debug("finishing job", nc.logger.Debug("finishing job",
zap.String("account#account_id", id), zap.String("account#reddit_account_id", id),
zap.String("account#username", account.NormalizedUsername()), zap.String("account#username", account.NormalizedUsername()),
) )
} }