fix(observabillity): propagate ctx to every log call and add resource to logging
This commit was merged in pull request #187.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/smtp"
|
||||
@@ -9,7 +10,7 @@ import (
|
||||
|
||||
type Mail interface {
|
||||
// Sending an email is a fire and forget operation. Thus no error handling
|
||||
SendMail(to string, subject string, message string)
|
||||
SendMail(ctx context.Context, to string, subject string, message string)
|
||||
}
|
||||
|
||||
type MailImpl struct {
|
||||
@@ -20,11 +21,11 @@ func NewMail(server *types.Settings) MailImpl {
|
||||
return MailImpl{server: server}
|
||||
}
|
||||
|
||||
func (m MailImpl) SendMail(to string, subject string, message string) {
|
||||
go m.internalSendMail(to, subject, message)
|
||||
func (m MailImpl) SendMail(ctx context.Context, to string, subject string, message string) {
|
||||
go m.internalSendMail(ctx, to, subject, message)
|
||||
}
|
||||
|
||||
func (m MailImpl) internalSendMail(to string, subject string, message string) {
|
||||
func (m MailImpl) internalSendMail(ctx context.Context, to string, subject string, message string) {
|
||||
if m.server.Smtp == nil {
|
||||
return
|
||||
}
|
||||
@@ -47,9 +48,9 @@ func (m MailImpl) internalSendMail(to string, subject string, message string) {
|
||||
subject,
|
||||
message)
|
||||
|
||||
slog.Info("sending mail", "to", to)
|
||||
slog.InfoContext(ctx, "sending mail", "to", to)
|
||||
err := smtp.SendMail(s.Host+":"+s.Port, auth, s.FromMail, []string{to}, []byte(msg))
|
||||
if err != nil {
|
||||
slog.Error("Error sending mail", "err", err)
|
||||
slog.ErrorContext(ctx, "Error sending mail", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user