Skip to content

Commit

Permalink
feat: add NID to logs in courier (#2956)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainStandby committed Dec 16, 2022
1 parent ac05259 commit b407aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions courier/courier_dispatcher.go
Expand Up @@ -14,6 +14,7 @@ func (c *courier) DispatchMessage(ctx context.Context, msg Message) error {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to increment the message's "send_count" field`)
return err
}
Expand All @@ -35,12 +36,14 @@ func (c *courier) DispatchMessage(ctx context.Context, msg Message) error {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to set the message status to "sent".`)
return err
}

c.deps.Logger().
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
WithField("message_type", msg.Type).
WithField("message_template_type", msg.TemplateType).
WithField("message_subject", msg.Subject).
Expand All @@ -66,12 +69,14 @@ func (c *courier) DispatchQueue(ctx context.Context) error {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to set the retried message's status to "abandoned".`)
return err
}
// Skip the message
c.deps.Logger().
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Warnf(`Message was abandoned because it did not deliver after %d attempts`, msg.SendCount)

} else if err := c.DispatchMessage(ctx, msg); err != nil {
Expand All @@ -80,6 +85,7 @@ func (c *courier) DispatchQueue(ctx context.Context) error {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to record failure log entry.`)
}

Expand All @@ -91,6 +97,7 @@ func (c *courier) DispatchQueue(ctx context.Context) error {
c.deps.Logger().
WithError(err).
WithField("message_id", replace.ID).
WithField("message_nid", replace.NID).
Error(`Unable to reset the failed message's status to "queued".`)
}
}
Expand All @@ -100,6 +107,7 @@ func (c *courier) DispatchQueue(ctx context.Context) error {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to record success log entry.`)
// continue with execution, as the message was successfully dispatched
}
Expand Down
6 changes: 6 additions & 0 deletions courier/smtp.go
Expand Up @@ -186,13 +186,15 @@ func (c *courier) dispatchEmail(ctx context.Context, msg Message) error {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to get email template from message.`)
} else {
htmlBody, err := tmpl.EmailBody(ctx)
if err != nil {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to get email body from template.`)
} else {
gm.AddAlternative("text/html", htmlBody)
Expand All @@ -205,6 +207,8 @@ func (c *courier) dispatchEmail(ctx context.Context, msg Message) error {
WithField("smtp_server", fmt.Sprintf("%s:%d", c.smtpClient.Host, c.smtpClient.Port)).
WithField("smtp_ssl_enabled", c.smtpClient.SSL).
WithField("message_from", from).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error("Unable to send email using SMTP connection.")

var protoErr *textproto.Error
Expand All @@ -215,6 +219,7 @@ func (c *courier) dispatchEmail(ctx context.Context, msg Message) error {
c.deps.Logger().
WithError(err).
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
Error(`Unable to reset the retried message's status to "abandoned".`)
return err
}
Expand All @@ -225,6 +230,7 @@ func (c *courier) dispatchEmail(ctx context.Context, msg Message) error {

c.deps.Logger().
WithField("message_id", msg.ID).
WithField("message_nid", msg.NID).
WithField("message_type", msg.Type).
WithField("message_template_type", msg.TemplateType).
WithField("message_subject", msg.Subject).
Expand Down

0 comments on commit b407aa9

Please sign in to comment.