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:
@@ -138,7 +138,7 @@ func (service AuthImpl) SignInAnonymous(ctx context.Context) (*types.Session, er
|
||||
return nil, types.ErrInternal
|
||||
}
|
||||
|
||||
slog.Info("anonymous session created", "session-id", session.Id)
|
||||
slog.InfoContext(ctx, "anonymous session created", "session-id", session.Id)
|
||||
|
||||
return session, nil
|
||||
}
|
||||
@@ -153,12 +153,12 @@ func (service AuthImpl) SignUp(ctx context.Context, email string, password strin
|
||||
return nil, ErrInvalidPassword
|
||||
}
|
||||
|
||||
userId, err := service.random.UUID()
|
||||
userId, err := service.random.UUID(ctx)
|
||||
if err != nil {
|
||||
return nil, types.ErrInternal
|
||||
}
|
||||
|
||||
salt, err := service.random.Bytes(16)
|
||||
salt, err := service.random.Bytes(ctx, 16)
|
||||
if err != nil {
|
||||
return nil, types.ErrInternal
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (service AuthImpl) SendVerificationMail(ctx context.Context, userId uuid.UU
|
||||
}
|
||||
|
||||
if token == nil {
|
||||
newTokenStr, err := service.random.String(32)
|
||||
newTokenStr, err := service.random.String(ctx, 32)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -214,11 +214,11 @@ func (service AuthImpl) SendVerificationMail(ctx context.Context, userId uuid.UU
|
||||
var w strings.Builder
|
||||
err = mailTemplate.Register(service.serverSettings.BaseUrl, token.Token).Render(context.Background(), &w)
|
||||
if err != nil {
|
||||
slog.Error("Could not render welcome email", "err", err)
|
||||
slog.ErrorContext(ctx, "Could not render welcome email", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
service.mail.SendMail(email, "Welcome to spend-sparrow", w.String())
|
||||
service.mail.SendMail(ctx, email, "Welcome to spend-sparrow", w.String())
|
||||
}
|
||||
|
||||
func (service AuthImpl) VerifyUserEmail(ctx context.Context, tokenStr string) error {
|
||||
@@ -278,7 +278,7 @@ func (service AuthImpl) DeleteAccount(ctx context.Context, user *types.User, cur
|
||||
return err
|
||||
}
|
||||
|
||||
service.mail.SendMail(user.Email, "Account deleted", "Your account has been deleted")
|
||||
service.mail.SendMail(ctx, user.Email, "Account deleted", "Your account has been deleted")
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -323,7 +323,7 @@ func (service AuthImpl) ChangePassword(ctx context.Context, user *types.User, se
|
||||
}
|
||||
|
||||
func (service AuthImpl) SendForgotPasswordMail(ctx context.Context, email string) error {
|
||||
tokenStr, err := service.random.String(32)
|
||||
tokenStr, err := service.random.String(ctx, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -353,10 +353,10 @@ func (service AuthImpl) SendForgotPasswordMail(ctx context.Context, email string
|
||||
var mail strings.Builder
|
||||
err = mailTemplate.ResetPassword(service.serverSettings.BaseUrl, token.Token).Render(context.Background(), &mail)
|
||||
if err != nil {
|
||||
slog.Error("Could not render reset password email", "err", err)
|
||||
slog.ErrorContext(ctx, "Could not render reset password email", "err", err)
|
||||
return types.ErrInternal
|
||||
}
|
||||
service.mail.SendMail(email, "Reset Password", mail.String())
|
||||
service.mail.SendMail(ctx, email, "Reset Password", mail.String())
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -383,7 +383,7 @@ func (service AuthImpl) ForgotPassword(ctx context.Context, tokenStr string, new
|
||||
|
||||
user, err := service.db.GetUser(ctx, token.UserId)
|
||||
if err != nil {
|
||||
slog.Error("Could not get user from token", "err", err)
|
||||
slog.ErrorContext(ctx, "Could not get user from token", "err", err)
|
||||
return types.ErrInternal
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ func (service AuthImpl) GetCsrfToken(ctx context.Context, session *types.Session
|
||||
return tokens[0].Token, nil
|
||||
}
|
||||
|
||||
tokenStr, err := service.random.String(32)
|
||||
tokenStr, err := service.random.String(ctx, 32)
|
||||
if err != nil {
|
||||
return "", types.ErrInternal
|
||||
}
|
||||
@@ -453,7 +453,7 @@ func (service AuthImpl) GetCsrfToken(ctx context.Context, session *types.Session
|
||||
return "", types.ErrInternal
|
||||
}
|
||||
|
||||
slog.Info("CSRF-Token created", "token", tokenStr)
|
||||
slog.InfoContext(ctx, "CSRF-Token created", "token", tokenStr)
|
||||
|
||||
return tokenStr, nil
|
||||
}
|
||||
@@ -473,7 +473,7 @@ func (service AuthImpl) CleanupSessionsAndTokens(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (service AuthImpl) createSession(ctx context.Context, userId uuid.UUID) (*types.Session, error) {
|
||||
sessionId, err := service.random.String(32)
|
||||
sessionId, err := service.random.String(ctx, 32)
|
||||
if err != nil {
|
||||
return nil, types.ErrInternal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user